Skip to content

Commit

Permalink
split_test: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
YuJuncen committed Oct 8, 2021
1 parent e9a882c commit 9aad9ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
9 changes: 2 additions & 7 deletions br/pkg/restore/split_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,13 +601,8 @@ func pdErrorCanRetry(err error) bool {
if grpcErr == nil {
return false
}
if strings.Contains(grpcErr.Message(), "is not fully replicated") {
return true
}
if strings.Contains(grpcErr.Message(), "has no leader") {
return true
}
return false
return strings.Contains(grpcErr.Message(), "is not fully replicated") ||
strings.Contains(grpcErr.Message(), "has no leader")
}

// NextBackoff returns a duration to wait before retrying again.
Expand Down
14 changes: 7 additions & 7 deletions br/pkg/restore/split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,22 @@ func (c *TestClient) SetStoresLabel(ctx context.Context, stores []uint64, labelK
return nil
}

type assertRetryNotThanBackoffer struct {
type assertRetryLessThanBackoffer struct {
max int
already int
t *testing.T
}

func assertRetryNotThan(t *testing.T, times int) utils.Backoffer {
return &assertRetryNotThanBackoffer{
func assertRetryLessThan(t *testing.T, times int) utils.Backoffer {
return &assertRetryLessThanBackoffer{
max: times,
already: 0,
t: t,
}
}

// NextBackoff returns a duration to wait before retrying again
func (b *assertRetryNotThanBackoffer) NextBackoff(err error) time.Duration {
func (b *assertRetryLessThanBackoffer) NextBackoff(err error) time.Duration {
b.already++
if b.already >= b.max {
b.t.Logf("retry more than %d time: test failed", b.max)
Expand All @@ -232,7 +232,7 @@ func (b *assertRetryNotThanBackoffer) NextBackoff(err error) time.Duration {
}

// Attempt returns the remain attempt times
func (b *assertRetryNotThanBackoffer) Attempt() int {
func (b *assertRetryLessThanBackoffer) Attempt() int {
return b.max - b.already
}

Expand Down Expand Up @@ -261,7 +261,7 @@ func TestScatterFinishInTime(t *testing.T) {
}
failed := map[uint64]int{}
client.injectInScatter = func(r *restore.RegionInfo) error {
failed[r.Region.Id] = failed[r.Region.Id] + 1
failed[r.Region.Id]++
if failed[r.Region.Id] > 7 {
return nil
}
Expand All @@ -272,7 +272,7 @@ func TestScatterFinishInTime(t *testing.T) {
// it would cost time unacceptable.
regionSplitter.ScatterRegionsWithBackoffer(ctx,
regionInfos,
assertRetryNotThan(t, 40))
assertRetryLessThan(t, 40))

}

Expand Down

0 comments on commit 9aad9ec

Please sign in to comment.