From 39f61e96266b97b81ea0ca3130526b6dae9f7000 Mon Sep 17 00:00:00 2001 From: "xinfei.wu" Date: Thu, 20 Dec 2018 17:42:06 +0800 Subject: [PATCH] remove subscriber testing --- http_test.go | 68 ---------------------------------------------------- 1 file changed, 68 deletions(-) diff --git a/http_test.go b/http_test.go index 33f77ed..f5346f4 100644 --- a/http_test.go +++ b/http_test.go @@ -1,17 +1,11 @@ package http import ( - "context" "fmt" "io/ioutil" "net/http" "testing" - "time" - api "github.com/micro/go-api/proto" - micro "github.com/micro/go-micro" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/client" "github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry/mock" "github.com/micro/go-micro/server" @@ -93,65 +87,3 @@ func TestHTTPServer(t *testing.T) { t.Fatal(err) } } - -func TestSubscriber(t *testing.T) { - reg := mock.NewRegistry() - - // create server - srv := NewServer( - server.Registry(reg), - server.Broker(broker.NewBroker(broker.Registry(reg))), - ) - - // register handler - if err := srv.Handle(srv.NewHandler(http.NewServeMux())); err != nil { - t.Fatal(err) - } - - // start server - if err := srv.Start(); err != nil { - t.Fatal(err) - } - - topic := "topic" - ctx, cancel := context.WithTimeout(context.TODO(), time.Millisecond*10) - sub := srv.NewSubscriber(topic, func(context.Context, *api.Event) error { - cancel() - return nil - }) - // subscribe - if err := srv.Subscribe(sub); err != nil { - t.Fatal(err) - } - - // register server - if err := srv.Register(); err != nil { - t.Fatal(err) - } - - // publish - 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") - } - - // deregister server - if err := srv.Deregister(); err != nil { - t.Fatal(err) - } - - // stop server - if err := srv.Stop(); err != nil { - t.Fatal(err) - } -}