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 {