Skip to content

Commit

Permalink
mvcc: update ut for Revisions/CountRevisions
Browse files Browse the repository at this point in the history
It is kind of backport from etcd-io#14124.

Signed-off-by: Wei Fu <fuweid89@gmail.com>
  • Loading branch information
fuweid committed Jan 18, 2023
1 parent 1246c52 commit 931cf9a
Showing 1 changed file with 38 additions and 18 deletions.
56 changes: 38 additions & 18 deletions mvcc/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,60 +206,80 @@ func TestIndexRevision(t *testing.T) {
tests := []struct {
key, end []byte
atRev int64
limit int
wrevs []revision
wcounts int
}{
// single key that not found
{
[]byte("bar"), nil, 6, nil, 0,
[]byte("bar"), nil, 6, 0, nil, 0,
},
// single key that found
{
[]byte("foo"), nil, 6, []revision{{main: 6}}, 1,
[]byte("foo"), nil, 6, 0, []revision{{main: 6}}, 1,
},
// various range keys, fixed atRev
// various range keys, fixed atRev, unlimited
{
[]byte("foo"), []byte("foo1"), 6, []revision{{main: 6}}, 1,
[]byte("foo"), []byte("foo1"), 6, 0, []revision{{main: 6}}, 1,
},
{
[]byte("foo"), []byte("foo2"), 6, []revision{{main: 6}, {main: 5}}, 2,
[]byte("foo"), []byte("foo2"), 6, 0, []revision{{main: 6}, {main: 5}}, 2,
},
{
[]byte("foo"), []byte("fop"), 6, []revision{{main: 6}, {main: 5}, {main: 4}}, 3,
[]byte("foo"), []byte("fop"), 6, 0, []revision{{main: 6}, {main: 5}, {main: 4}}, 3,
},
{
[]byte("foo1"), []byte("fop"), 6, []revision{{main: 5}, {main: 4}}, 2,
[]byte("foo1"), []byte("fop"), 6, 0, []revision{{main: 5}, {main: 4}}, 2,
},
{
[]byte("foo2"), []byte("fop"), 6, []revision{{main: 4}}, 1,
[]byte("foo2"), []byte("fop"), 6, 0, []revision{{main: 4}}, 1,
},
{
[]byte("foo3"), []byte("fop"), 6, nil, 0,
[]byte("foo3"), []byte("fop"), 6, 0, nil, 0,
},
// fixed range keys, various atRev
// fixed range keys, various atRev, unlimited
{
[]byte("foo1"), []byte("fop"), 1, nil, 0,
[]byte("foo1"), []byte("fop"), 1, 0, nil, 0,
},
{
[]byte("foo1"), []byte("fop"), 2, []revision{{main: 2}}, 1,
[]byte("foo1"), []byte("fop"), 2, 0, []revision{{main: 2}}, 1,
},
{
[]byte("foo1"), []byte("fop"), 3, []revision{{main: 2}, {main: 3}}, 2,
[]byte("foo1"), []byte("fop"), 3, 0, []revision{{main: 2}, {main: 3}}, 2,
},
{
[]byte("foo1"), []byte("fop"), 4, []revision{{main: 2}, {main: 4}}, 2,
[]byte("foo1"), []byte("fop"), 4, 0, []revision{{main: 2}, {main: 4}}, 2,
},
{
[]byte("foo1"), []byte("fop"), 5, []revision{{main: 5}, {main: 4}}, 2,
[]byte("foo1"), []byte("fop"), 5, 0, []revision{{main: 5}, {main: 4}}, 2,
},
{
[]byte("foo1"), []byte("fop"), 6, []revision{{main: 5}, {main: 4}}, 2,
[]byte("foo1"), []byte("fop"), 6, 0, []revision{{main: 5}, {main: 4}}, 2,
},
// fixed range keys, fixed atRev, various limit
{
[]byte("foo"), []byte("fop"), 6, 1, []revision{{main: 6}}, 3,
},
{
[]byte("foo"), []byte("fop"), 6, 2, []revision{{main: 6}, {main: 5}}, 3,
},
{
[]byte("foo"), []byte("fop"), 6, 3, []revision{{main: 6}, {main: 5}, {main: 4}}, 3,
},
{
[]byte("foo"), []byte("fop"), 3, 1, []revision{{main: 1}}, 3,
},
{
[]byte("foo"), []byte("fop"), 3, 2, []revision{{main: 1}, {main: 2}}, 3,
},
{
[]byte("foo"), []byte("fop"), 3, 3, []revision{{main: 1}, {main: 2}, {main: 3}}, 3,
},
}
for i, tt := range tests {
revs := ti.Revisions(tt.key, tt.end, tt.atRev)
revs, _ := ti.Revisions(tt.key, tt.end, tt.atRev, tt.limit)
if !reflect.DeepEqual(revs, tt.wrevs) {
t.Errorf("#%d: revs = %+v, want %+v", i, revs, tt.wrevs)
t.Errorf("#%d limit %d: revs = %+v, want %+v", i, tt.limit, revs, tt.wrevs)
}
count := ti.CountRevisions(tt.key, tt.end, tt.atRev)
if count != tt.wcounts {
Expand Down

0 comments on commit 931cf9a

Please sign in to comment.