Skip to content

Commit b4c8749

Browse files
authored
br: fix flaky test (#52573)
close #52547
1 parent ecb8a9e commit b4c8749

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

br/pkg/restore/client_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ func TestGetTSWithRetry(t *testing.T) {
408408
})
409409

410410
t.Run("PD leader failure:", func(t *testing.T) {
411+
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/br/pkg/utils/set-attempt-to-one", "1*return(true)"))
412+
defer func() {
413+
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/br/pkg/utils/set-attempt-to-one"))
414+
}()
411415
retryTimes := -1000
412416
pDClient := fakePDClient{notLeader: true, retryTimes: &retryTimes}
413417
client := restore.NewRestoreClient(pDClient, nil, nil, defaultKeepaliveCfg)

br/pkg/utils/backoff.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/pingcap/errors"
14+
"github.com/pingcap/failpoint"
1415
"github.com/pingcap/log"
1516
berrors "github.com/pingcap/tidb/br/pkg/errors"
1617
"go.uber.org/zap"
@@ -264,6 +265,9 @@ func (bo *pdReqBackoffer) NextBackoff(err error) time.Duration {
264265
}
265266
}
266267

268+
failpoint.Inject("set-attempt-to-one", func(_ failpoint.Value) {
269+
bo.attempt = 1
270+
})
267271
if bo.delayTime > bo.maxDelayTime {
268272
return bo.maxDelayTime
269273
}

0 commit comments

Comments
 (0)