etcdserver: Fix invalid count returned on Range with Limit

This commit is contained in:
Marek Siarkowicz
2021-05-31 17:25:57 +02:00
parent 6cd7c02873
commit 9a18742bd7
5 changed files with 54 additions and 36 deletions

View File

@@ -221,17 +221,18 @@ func testKVRangeLimit(t *testing.T, f rangeFunc) {
wrev := int64(4)
tests := []struct {
limit int64
wkvs []mvccpb.KeyValue
limit int64
wcounts int64
wkvs []mvccpb.KeyValue
}{
// no limit
{-1, kvs},
{-1, 3, kvs},
// no limit
{0, kvs},
{1, kvs[:1]},
{2, kvs[:2]},
{3, kvs},
{100, kvs},
{0, 3, kvs},
{1, 3, kvs[:1]},
{2, 3, kvs[:2]},
{3, 3, kvs},
{100, 3, kvs},
}
for i, tt := range tests {
r, err := f(s, []byte("foo"), []byte("foo3"), RangeOptions{Limit: tt.limit})
@@ -248,7 +249,7 @@ func testKVRangeLimit(t *testing.T, f rangeFunc) {
if r.Count != len(kvs) {
t.Errorf("#%d: count = %d, want %d", i, r.Count, len(kvs))
}
} else if r.Count != int(tt.limit) {
} else if r.Count != int(tt.wcounts) {
t.Errorf("#%d: count = %d, want %d", i, r.Count, tt.limit)
}
}