Skip to content
This repository was archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
fix comment and add a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
glorv committed Oct 19, 2020
1 parent 1cfa0b3 commit ca5989b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lightning/backend/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ func (local *local) isIngestRetryable(
}
}
return true, newRegion, errors.Errorf("not leader: %s", errPb.GetMessage())
case strings.Contains(errPb.Message, "Raft raft: proposal dropped"):
case strings.Contains(errPb.Message, "raft: proposal dropped"):
// TODO: we should change 'Raft raft: proposal dropped' to a error type like 'NotLeader'
newRegion, err = getRegion()
if err != nil {
Expand Down
33 changes: 33 additions & 0 deletions lightning/backend/local_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package backend

import (
"bytes"

. "github.com/pingcap/check"
)

type localSuite struct{}

var _ = Suite(&localSuite{})

func (s *localSuite) TestNextKey(c *C) {
c.Assert(nextKey([]byte{}), Equals, []byte{})

cases := [][]byte{
[]byte{0},
[]byte{255},
[]byte{1, 255},
}
for _, b := range cases {
next := nextKey(b)
c.Assert(next, Equals, append(b, 0))
}

// in the old logic, this should return []byte{} which is not the actually smallest eky
next := nextKey([]byte{1, 255})
c.Assert(bytes.Compare(next, []byte{2}), Equals, -1)

// another test case, nextkey()'s return should be smaller than key with a prefix of the origin key
next = nextKey([]byte{1, 255})
c.Assert(bytes.Compare(next, []byte{1, 255, 0, 1, 2}), Equals, -1)
}

0 comments on commit ca5989b

Please sign in to comment.