Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
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.
57 changes: 57 additions & 0 deletions pkg/restore/backoff_test.go
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)
}

0 comments on commit d1ec365

Please sign in to comment.