From b87190d9dc4235bc052d03fd114dfeea81e1f799 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Mon, 7 Nov 2016 12:04:41 -0800 Subject: [PATCH] integration: test canceling a watcher on disconnected stream --- clientv3/integration/watch_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/clientv3/integration/watch_test.go b/clientv3/integration/watch_test.go index 1a432dfa1..1fd6e6b00 100644 --- a/clientv3/integration/watch_test.go +++ b/clientv3/integration/watch_test.go @@ -782,3 +782,22 @@ func TestWatchCancelAndCloseClient(t *testing.T) { <-donec clus.TakeClient(0) } + +// TestWatchCancelDisconnected ensures canceling a watcher works when +// its grpc stream is disconnected / reconnecting. +func TestWatchCancelDisconnected(t *testing.T) { + defer testutil.AfterTest(t) + clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1}) + defer clus.Terminate(t) + cli := clus.Client(0) + ctx, cancel := context.WithCancel(context.Background()) + // add more watches than can be resumed before the cancel + wch := cli.Watch(ctx, "abc") + clus.Members[0].Stop(t) + cancel() + select { + case <-wch: + case <-time.After(time.Second): + t.Fatal("took too long to cancel disconnected watcher") + } +}