remove subscriber testing

This commit is contained in:
xinfei.wu 2018-12-20 17:42:06 +08:00 committed by Vasiliy Tolstov
parent eeb05bc929
commit 39f61e9626

View File

@ -1,17 +1,11 @@
package http package http
import ( import (
"context"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"testing" "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"
"github.com/micro/go-micro/registry/mock" "github.com/micro/go-micro/registry/mock"
"github.com/micro/go-micro/server" "github.com/micro/go-micro/server"
@ -93,65 +87,3 @@ func TestHTTPServer(t *testing.T) {
t.Fatal(err) 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)
}
}