Skip to content

Commit

Permalink
integration: add TestV3HashKV in v3_grpc_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
fanminshi committed Jul 25, 2017
1 parent 2f9d3ca commit 32e64d4
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions integration/v3_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"math/rand"
"os"
"reflect"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -147,6 +148,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

var rev int64
for i := 0; i < 10; i++ {
resp, err := kvc.Put(context.Background(), &pb.PutRequest{Key: []byte("foo"), Value: []byte("bar" + strconv.Itoa(i))})
if err != nil {
t.Fatal(err)
}
rev = resp.Header.Revision
}

// ensure appliedIdx is sync with committedIdx
_, err := kvc.Range(context.Background(), &pb.RangeRequest{Key: []byte("foo")})
if err != nil {
t.Fatal(err)
}

var (
prevHash uint32
prevCompactRev int64
)
for i := 0; i < 10; i++ {
resp, err := mvc.HashKV(context.Background(), &pb.HashKVRequest{rev})
if err != nil {
t.Fatal(err)
}
if prevHash == 0 {
prevHash = resp.Hash
prevCompactRev = resp.CompactRevision
continue
}

if prevHash != resp.Hash {
t.Fatalf("prevHash %v != Hash %v", prevHash, resp.Hash)
}

if prevCompactRev != resp.CompactRevision {
t.Fatalf("prevCompactRev %v != CompactRevision %v", prevHash, resp.Hash)
}
}
}

func TestV3TxnTooManyOps(t *testing.T) {
defer testutil.AfterTest(t)
maxTxnOps := uint(128)
Expand Down

0 comments on commit 32e64d4

Please sign in to comment.