From d3de45409f9eb1c85671b985b4ea8c1c0e0a4191 Mon Sep 17 00:00:00 2001 From: Asim Date: Sun, 1 May 2016 22:30:33 +0100 Subject: [PATCH] Simplify watcher test --- registry/mdns/watcher_test.go | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/registry/mdns/watcher_test.go b/registry/mdns/watcher_test.go index 8cf00087..8b1335b8 100644 --- a/registry/mdns/watcher_test.go +++ b/registry/mdns/watcher_test.go @@ -100,64 +100,45 @@ func TestWatcher(t *testing.T) { t.Fatal(err) } - var ok bool - - for i := 0; i < 5; i++ { - // get registered service + for { res, err := w.Next() if err != nil { t.Fatal(err) } if res.Service.Name != service.Name { - break + continue } if res.Action != "create" { - break + t.Fatalf("Expected create event got %s for %s", res.Action, res.Service.Name) } testFn(service, res.Service) - ok = true break } - if !ok { - t.Fatalf("Watch test failed for creation of %s", service.Name) - } - } - - for _, service := range testData { // deregister if err := r.Deregister(service); err != nil { t.Fatal(err) } - var ok bool - - for i := 0; i < 5; i++ { - // get registered service + for { res, err := w.Next() if err != nil { t.Fatal(err) } + if res.Service.Name != service.Name { + continue + } + if res.Action != "delete" { continue } - if res.Service.Name != service.Name { - break - } - testFn(service, res.Service) - ok = true break } - - if !ok { - t.Fatalf("Watch test failed for deletion of %s", service.Name) - } } - }