From eeb05bc929afbbbaa8860e578374f61ca3c7e148 Mon Sep 17 00:00:00 2001 From: "xinfei.wu" Date: Thu, 20 Dec 2018 14:20:25 +0800 Subject: [PATCH] clean test code --- http_test.go | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/http_test.go b/http_test.go index 45c0a4c..33f77ed 100644 --- a/http_test.go +++ b/http_test.go @@ -5,7 +5,6 @@ import ( "fmt" "io/ioutil" "net/http" - "sync" "testing" "time" @@ -131,26 +130,19 @@ func TestSubscriber(t *testing.T) { } // publish - wg := sync.WaitGroup{} - go func() { - wg.Add(1) - defer wg.Done() - mClient := client.NewClient( - client.Registry(reg), - client.Transport(srv.Options().Transport), - client.Broker(srv.Options().Broker), - ) - pub := micro.NewPublisher(topic, mClient) - if err := pub.Publish(ctx, &api.Event{}); err != nil { - t.Fatal(err) - } - }() - wg.Wait() + mClient := client.NewClient( + client.Registry(reg), + client.Broker(srv.Options().Broker), + ) + pub := micro.NewPublisher(topic, mClient) + if err := pub.Publish(ctx, &api.Event{}); err != nil { + t.Fatal(err) + } // wait cancel <-ctx.Done() if ctx.Err() != context.Canceled { - t.Fatalf("subscriber is not working, err: %s", ctx.Err()) + t.Fatalf("subscriber is not working") } // deregister server