1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00

Simplify watcher test

This commit is contained in:
Asim 2016-05-01 22:30:33 +01:00
parent 7996785195
commit d3de45409f

View File

@ -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)
}
}
}