From 26d7b599e913778eaef3a12992fefb4380fa7036 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 --- watcher_test.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/watcher_test.go b/watcher_test.go index ab209f6..1a0cde7 100644 --- a/watcher_test.go +++ b/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}