Browse Source

clientv3/integration: test watcher cancelation propagation to server

Anthony Romano 9 years ago
parent
commit
8c1c291332
1 changed files with 24 additions and 0 deletions
  1. 24 0
      clientv3/integration/watch_test.go

+ 24 - 0
clientv3/integration/watch_test.go

@@ -727,3 +727,27 @@ func TestWatchWithCreatedNotification(t *testing.T) {
 		t.Fatalf("expected created event, got %v", resp)
 		t.Fatalf("expected created event, got %v", resp)
 	}
 	}
 }
 }
+
+// TestWatchCancelOnServer ensures client watcher cancels propagate back to the server.
+func TestWatchCancelOnServer(t *testing.T) {
+	cluster := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})
+	defer cluster.Terminate(t)
+
+	client := cluster.RandClient()
+
+	for i := 0; i < 10; i++ {
+		ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+		client.Watch(ctx, "a", clientv3.WithCreatedNotify())
+		cancel()
+	}
+	// wait for cancels to propagate
+	time.Sleep(time.Second)
+
+	watchers, err := cluster.Members[0].Metric("etcd_debugging_mvcc_watcher_total")
+	if err != nil {
+		t.Fatal(err)
+	}
+	if watchers != "0" {
+		t.Fatalf("expected 0 watchers, got %q", watchers)
+	}
+}