From 3709831d8e21eba0f962a022f9e344c66e4c0d14 Mon Sep 17 00:00:00 2001 From: Asim Date: Sun, 1 May 2016 21:38:22 +0100 Subject: [PATCH] Watch results may be unordered --- registry/mdns/watcher_test.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/registry/mdns/watcher_test.go b/registry/mdns/watcher_test.go index ab209f69..1a0cde71 100644 --- a/registry/mdns/watcher_test.go +++ b/registry/mdns/watcher_test.go @@ -66,7 +66,9 @@ func TestWatcher(t *testing.T) { if err := r.Register(service); err != nil { t.Fatal(err) } + } + for i := 0; i < 3; i++ { // get registered service res, err := w.Next() if err != nil { @@ -74,7 +76,20 @@ func TestWatcher(t *testing.T) { } if res.Action != "create" { - t.Fatal("Expected create action for %s", service.Name) + t.Fatal("Expected create action for %s", res.Service.Name) + } + + var service *registry.Service + + for _, srv := range testData { + if res.Service.Name == srv.Name { + service = res.Service + break + } + } + + if service == nil { + t.Fatal("Got watch result for unknown service %s", res.Service.Name) } s := []*registry.Service{res.Service} @@ -124,7 +139,20 @@ func TestWatcher(t *testing.T) { } if res.Action != "delete" { - t.Fatalf("Expected create action for %s", service.Name) + t.Fatalf("Expected create action for %s", res.Service.Name) + } + + var service *registry.Service + + for _, srv := range testData { + if res.Service.Name == srv.Name { + service = res.Service + break + } + } + + if service == nil { + t.Fatal("Got watch result for unknown service %s", res.Service.Name) } s := []*registry.Service{res.Service}