From 766c2540aecaaefc22a21cab64be1b521b0ed1f7 Mon Sep 17 00:00:00 2001 From: fanmin shi Date: Fri, 21 Jul 2017 10:53:07 -0700 Subject: [PATCH] integration: add TestV3HashKV in v3_grpc_test.go --- integration/v3_grpc_test.go | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/integration/v3_grpc_test.go b/integration/v3_grpc_test.go index 83b211578..3d77d8c9f 100644 --- a/integration/v3_grpc_test.go +++ b/integration/v3_grpc_test.go @@ -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)