From 8cd50dd005584d3d9e2620e966d92dd0ee540c7d Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Tue, 22 Dec 2015 14:48:08 +0100 Subject: [PATCH] Fix etcdWatcher test --- pkg/storage/etcd/etcd_watcher_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/storage/etcd/etcd_watcher_test.go b/pkg/storage/etcd/etcd_watcher_test.go index 23e4a59a161..41bda3fff95 100644 --- a/pkg/storage/etcd/etcd_watcher_test.go +++ b/pkg/storage/etcd/etcd_watcher_test.go @@ -266,8 +266,15 @@ func TestWatch(t *testing.T) { watching.Stop() - if _, open := <-watching.ResultChan(); open { - t.Errorf("An injected error did not cause a graceful shutdown") + // There is a race in etcdWatcher so that after calling Stop() one of + // two things can happen: + // - ResultChan() may be closed (triggered by closing userStop channel) + // - an Error "context cancelled" may be emitted (triggered by cancelling request + // to etcd and putting that error to etcdError channel) + // We need to be prepared for both here. + event, open := <-watching.ResultChan() + if open && event.Type != watch.Error { + t.Errorf("Unexpected event from stopped watcher: %#v", event) } }