Skip to content

Commit

Permalink
Merge pull request #6634 from gyuho/manual
Browse files Browse the repository at this point in the history
integration: add TestV3WatchWithPrevKV
  • Loading branch information
xiang90 authored Oct 12, 2016
2 parents 614adb0 + c394828 commit 354891f
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions integration/v3_watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1079,3 +1079,72 @@ func TestV3WatchWithFilter(t *testing.T) {
t.Fatal("failed to receive delete event")
}
}

func TestV3WatchWithPrevKV(t *testing.T) {
clus := NewClusterV3(t, &ClusterConfig{Size: 1})
defer clus.Terminate(t)

tests := []struct {
key string
end string
vals []string
}{{
key: "foo",
end: "fop",
vals: []string{"bar1", "bar2"},
}, {
key: "/abc",
end: "/abd",
vals: []string{"first", "second"},
}}
for i, tt := range tests {
kvc := toGRPC(clus.RandClient()).KV
if _, err := kvc.Put(context.TODO(), &pb.PutRequest{Key: []byte(tt.key), Value: []byte(tt.vals[0])}); err != nil {
t.Fatal(err)
}

ws, werr := toGRPC(clus.RandClient()).Watch.Watch(context.TODO())
if werr != nil {
t.Fatal(werr)
}

req := &pb.WatchRequest{RequestUnion: &pb.WatchRequest_CreateRequest{
CreateRequest: &pb.WatchCreateRequest{
Key: []byte(tt.key),
RangeEnd: []byte(tt.end),
PrevKv: true,
}}}
if err := ws.Send(req); err != nil {
t.Fatal(err)
}
if _, err := ws.Recv(); err != nil {
t.Fatal(err)
}

if _, err := kvc.Put(context.TODO(), &pb.PutRequest{Key: []byte(tt.key), Value: []byte(tt.vals[1])}); err != nil {
t.Fatal(err)
}

recv := make(chan *pb.WatchResponse)
go func() {
// check received PUT
resp, rerr := ws.Recv()
if rerr != nil {
t.Fatal(rerr)
}
recv <- resp
}()

select {
case resp := <-recv:
if tt.vals[1] != string(resp.Events[0].Kv.Value) {
t.Errorf("#%d: unequal value: want=%s, get=%s", i, tt.vals[1], resp.Events[0].Kv.Value)
}
if tt.vals[0] != string(resp.Events[0].PrevKv.Value) {
t.Errorf("#%d: unequal value: want=%s, get=%s", i, tt.vals[0], resp.Events[0].PrevKv.Value)
}
case <-time.After(30 * time.Second):
t.Error("timeout waiting for watch response")
}
}
}

0 comments on commit 354891f

Please sign in to comment.