Skip to content

Commit

Permalink
test: fix unstable test TestClearCache (#51480) (#53448)
Browse files Browse the repository at this point in the history
close #50743
  • Loading branch information
ti-chi-bot committed May 23, 2024
1 parent 001c1ff commit 9e0434f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions br/pkg/streamhelper/advancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func TestClearCache(t *testing.T) {
c.splitAndScatter("0012", "0034", "0048")

clearedCache := make(map[uint64]bool)
c.onGetClient = func(u uint64) error {
c.onClearCache = func(u uint64) error {
// make store u cache cleared
clearedCache[u] = true
return nil
Expand All @@ -270,7 +270,7 @@ func TestClearCache(t *testing.T) {
s.onGetRegionCheckpoint = func(glftrr *logbackup.GetLastFlushTSOfRegionRequest) error {
// mark this store cache cleared
failedStoreID = s.GetID()
if hasFailed {
if !hasFailed {
hasFailed = true
return errors.New("failed to get checkpoint")
}
Expand All @@ -287,7 +287,7 @@ func TestClearCache(t *testing.T) {
shouldFinishInTime(t, time.Second, "ticking", func() {
err = adv.OnTick(ctx)
})
req.NoError(err)
req.Error(err)
req.True(failedStoreID > 0, "failed to mark the cluster: ")
req.Equal(clearedCache[failedStoreID], true)
}
Expand Down
5 changes: 3 additions & 2 deletions br/pkg/streamhelper/basic_lib_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ type fakeCluster struct {
testCtx *testing.T

onGetClient func(uint64) error
onClearCache func(uint64) error
serviceGCSafePoint uint64
}

Expand Down Expand Up @@ -320,8 +321,8 @@ func (f *fakeCluster) GetLogBackupClient(ctx context.Context, storeID uint64) (l
}

func (f *fakeCluster) ClearCache(ctx context.Context, storeID uint64) error {
if f.onGetClient != nil {
err := f.onGetClient(storeID)
if f.onClearCache != nil {
err := f.onClearCache(storeID)
if err != nil {
return err
}
Expand Down

0 comments on commit 9e0434f

Please sign in to comment.