integration: add TestV3HashKV in v3_grpc_test.go

release-3.3
fanmin shi 2017-07-21 10:53:07 -07:00
parent a6ae677d8f
commit 766c2540ae
1 changed files with 49 additions and 0 deletions

View File

@ -147,6 +147,55 @@ func TestV3CompactCurrentRev(t *testing.T) {
}
}
// TestV3HashKV ensures that multiple calls of HashKV on same node return same hash and compact rev.
func TestV3HashKV(t *testing.T) {
defer testutil.AfterTest(t)
clus := NewClusterV3(t, &ClusterConfig{Size: 1})
defer clus.Terminate(t)
kvc := toGRPC(clus.RandClient()).KV
mvc := toGRPC(clus.RandClient()).Maintenance
for i := 0; i < 10; i++ {
resp, err := kvc.Put(context.Background(), &pb.PutRequest{Key: []byte("foo"), Value: []byte(fmt.Sprintf("bar%d", i))})
if err != nil {
t.Fatal(err)
}
rev := resp.Header.Revision
hresp, err := mvc.HashKV(context.Background(), &pb.HashKVRequest{0})
if err != nil {
t.Fatal(err)
}
if rev != hresp.Header.Revision {
t.Fatalf("Put rev %v != HashKV rev %v", rev, hresp.Header.Revision)
}
prevHash := hresp.Hash
prevCompactRev := hresp.CompactRevision
for i := 0; i < 10; i++ {
hresp, err := mvc.HashKV(context.Background(), &pb.HashKVRequest{0})
if err != nil {
t.Fatal(err)
}
if rev != hresp.Header.Revision {
t.Fatalf("Put rev %v != HashKV rev %v", rev, hresp.Header.Revision)
}
if prevHash != hresp.Hash {
t.Fatalf("prevHash %v != Hash %v", prevHash, hresp.Hash)
}
if prevCompactRev != hresp.CompactRevision {
t.Fatalf("prevCompactRev %v != CompactRevision %v", prevHash, hresp.Hash)
}
prevHash = hresp.Hash
prevCompactRev = hresp.CompactRevision
}
}
}
func TestV3TxnTooManyOps(t *testing.T) {
defer testutil.AfterTest(t)
maxTxnOps := uint(128)