Skip to content

Commit

Permalink
br: fix flaky test (#52573) (#52665)
Browse files Browse the repository at this point in the history
close #52547
  • Loading branch information
ti-chi-bot authored May 7, 2024
1 parent c8e6662 commit 238f2e6
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 @@ -408,6 +408,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, 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 @@ -11,6 +11,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 @@ -264,6 +265,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 238f2e6

Please sign in to comment.