Skip to content

Commit

Permalink
br: fix flaky test (#52573) (#52667)
Browse files Browse the repository at this point in the history
close #52547
  • Loading branch information
ti-chi-bot authored Jun 6, 2024
1 parent 83bef61 commit 460a563
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions br/pkg/restore/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@ func TestGetTSWithRetry(t *testing.T) {
})

t.Run("PD leader failure:", func(t *testing.T) {
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/br/pkg/utils/set-attempt-to-one", "1*return(true)"))
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/br/pkg/utils/set-attempt-to-one"))
}()
retryTimes := -1000
pDClient := fakePDClient{notLeader: true, retryTimes: &retryTimes}
client := restore.NewRestoreClient(pDClient, nil, defaultKeepaliveCfg, false)
Expand Down
4 changes: 4 additions & 0 deletions br/pkg/utils/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/log"
berrors "github.com/pingcap/tidb/br/pkg/errors"
"go.uber.org/zap"
Expand Down Expand Up @@ -239,6 +240,9 @@ func (bo *pdReqBackoffer) NextBackoff(err error) time.Duration {
}
}

failpoint.Inject("set-attempt-to-one", func(_ failpoint.Value) {
bo.attempt = 1
})
if bo.delayTime > bo.maxDelayTime {
return bo.maxDelayTime
}
Expand Down

0 comments on commit 460a563

Please sign in to comment.