From 00ce0116c5778f0c9df74e0420c78db2d5d6b2a9 Mon Sep 17 00:00:00 2001 From: greenmoon55 Date: Wed, 8 Nov 2023 00:00:23 -0600 Subject: [PATCH 1/2] tests: add comments for clientv3test.TestWatchResumeInitRev Signed-off-by: Jin Dong --- tests/integration/clientv3/watch_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/integration/clientv3/watch_test.go b/tests/integration/clientv3/watch_test.go index 28e0faa41f3..335a2007a10 100644 --- a/tests/integration/clientv3/watch_test.go +++ b/tests/integration/clientv3/watch_test.go @@ -350,6 +350,8 @@ func putAndWatch(t *testing.T, wctx *watchctx, key, val string) { } } +// TestWatchResumeInitRev tests watch resume with disconnect before the first event. +// It ensures that correct events are returned corresponding to the start revision. func TestWatchResumeInitRev(t *testing.T) { integration2.BeforeTest(t) clus := integration2.NewCluster(t, &integration2.ClusterConfig{Size: 1, UseBridge: true}) @@ -367,7 +369,10 @@ func TestWatchResumeInitRev(t *testing.T) { t.Fatal(err) } + // watch from revision 1 wch := clus.Client(0).Watch(context.Background(), "a", clientv3.WithRev(1), clientv3.WithCreatedNotify()) + // response for the create watch request, no events are in this response + // the current revision of etcd should be 4 if resp, ok := <-wch; !ok || resp.Header.Revision != 4 { t.Fatalf("got (%v, %v), expected create notification rev=4", resp, ok) } @@ -392,6 +397,7 @@ func TestWatchResumeInitRev(t *testing.T) { if len(resp.Events) == 0 { t.Fatal("expected event on watch") } + // Events should be put(a, 3) and put(a, 4) if string(resp.Events[0].Kv.Value) != "3" { t.Fatalf("expected value=3, got event %+v", resp.Events[0]) } From 4c853774e670871d1f400f68d80b15d03d82f366 Mon Sep 17 00:00:00 2001 From: Jin Dong Date: Tue, 28 Nov 2023 02:32:15 +0000 Subject: [PATCH 2/2] Rename the test and update comments Signed-off-by: Jin Dong --- tests/integration/clientv3/watch_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/integration/clientv3/watch_test.go b/tests/integration/clientv3/watch_test.go index 335a2007a10..bc76c8187d8 100644 --- a/tests/integration/clientv3/watch_test.go +++ b/tests/integration/clientv3/watch_test.go @@ -350,9 +350,9 @@ func putAndWatch(t *testing.T, wctx *watchctx, key, val string) { } } -// TestWatchResumeInitRev tests watch resume with disconnect before the first event. -// It ensures that correct events are returned corresponding to the start revision. -func TestWatchResumeInitRev(t *testing.T) { +// TestWatchResumeAfterDisconnect tests watch resume after member disconnects then connects. +// It ensures that correct events are returned corresponding to the start revision. +func TestWatchResumeAfterDisconnect(t *testing.T) { integration2.BeforeTest(t) clus := integration2.NewCluster(t, &integration2.ClusterConfig{Size: 1, UseBridge: true}) defer clus.Terminate(t) @@ -394,13 +394,16 @@ func TestWatchResumeInitRev(t *testing.T) { if !ok { t.Fatal("unexpected watch close") } - if len(resp.Events) == 0 { - t.Fatal("expected event on watch") - } // Events should be put(a, 3) and put(a, 4) + if len(resp.Events) != 2 { + t.Fatal("expected two events on watch") + } if string(resp.Events[0].Kv.Value) != "3" { t.Fatalf("expected value=3, got event %+v", resp.Events[0]) } + if string(resp.Events[1].Kv.Value) != "4" { + t.Fatalf("expected value=4, got event %+v", resp.Events[1]) + } case <-time.After(5 * time.Second): t.Fatal("watch timed out") }