From cee5b53423291ee029c9ab40424d56f8bc8965b7 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Thu, 14 May 2015 18:32:19 -0700 Subject: [PATCH] consul: adding StopWatch test --- consul/state_store_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/consul/state_store_test.go b/consul/state_store_test.go index 30416eaa5d..97592c11d5 100644 --- a/consul/state_store_test.go +++ b/consul/state_store_test.go @@ -127,6 +127,37 @@ func TestGetNodes(t *testing.T) { } } +func TestGetNodes_Watch_StopWatch(t *testing.T) { + store, err := testStateStore() + if err != nil { + t.Fatalf("err: %v", err) + } + defer store.Close() + + notify1 := make(chan struct{}, 1) + notify2 := make(chan struct{}, 1) + + store.Watch(store.QueryTables("Nodes"), notify1) + store.Watch(store.QueryTables("Nodes"), notify2) + store.StopWatch(store.QueryTables("Nodes"), notify2) + + if err := store.EnsureNode(40, structs.Node{"foo", "127.0.0.1"}); err != nil { + t.Fatalf("err: %v", err) + } + + select { + case <-notify1: + default: + t.Fatalf("should be notified") + } + + select { + case <-notify2: + t.Fatalf("should not be notified") + default: + } +} + func BenchmarkGetNodes(b *testing.B) { store, err := testStateStore() if err != nil {