This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: 5kbpers <[email protected]>
- Loading branch information
5kbpers
committed
Feb 4, 2020
1 parent
3e939c8
commit d1ec365
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package restore | ||
|
||
import ( | ||
"time" | ||
|
||
. "github.com/pingcap/check" | ||
"github.com/pingcap/tidb/util/testleak" | ||
|
||
"github.com/pingcap/br/pkg/utils" | ||
) | ||
|
||
var _ = Suite(&testBackofferSuite{}) | ||
|
||
type testBackofferSuite struct { | ||
mock *utils.MockCluster | ||
} | ||
|
||
func (s *testBackofferSuite) SetUpSuite(c *C) { | ||
var err error | ||
s.mock, err = utils.NewMockCluster() | ||
c.Assert(err, IsNil) | ||
} | ||
|
||
func (s *testBackofferSuite) TearDownSuite(c *C) { | ||
testleak.AfterTest(c)() | ||
} | ||
|
||
func (s *testBackofferSuite) TestImporterBackoffer(c *C) { | ||
var counter int | ||
err := utils.WithRetry(func() error { | ||
defer func() { counter++ }() | ||
switch counter { | ||
case 0: | ||
return errGrpc | ||
case 1: | ||
return errResp | ||
case 2: | ||
return errRangeIsEmpty | ||
} | ||
return nil | ||
}, newImportSSTBackoffer()) | ||
c.Assert(counter, Equals, 3) | ||
c.Assert(err, Equals, errRangeIsEmpty) | ||
|
||
counter = 0 | ||
backoffer := importerBackoffer{ | ||
attempt: 10, | ||
delayTime: time.Nanosecond, | ||
maxDelayTime: time.Nanosecond, | ||
} | ||
err = utils.WithRetry(func() error { | ||
defer func() { counter++ }() | ||
return errResp | ||
}, &backoffer) | ||
c.Assert(counter, Equals, 10) | ||
c.Assert(err, Equals, errResp) | ||
} |