1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-24 22:26:54 +02:00

Moving to gRPC by default (#1069)

* Step 1

* Fix the test panics
This commit is contained in:
Asim Aslam
2019-12-29 21:07:55 +00:00
committed by GitHub
parent 943445270f
commit c145f355dd
16 changed files with 273 additions and 259 deletions

View File

@ -7,8 +7,8 @@ import (
"testing"
"time"
"github.com/micro/go-micro"
"github.com/micro/go-micro/registry/memory"
"github.com/micro/go-micro/service"
hello "github.com/micro/go-micro/service/grpc/proto"
mls "github.com/micro/go-micro/util/tls"
)
@ -32,13 +32,13 @@ func TestGRPCService(t *testing.T) {
// create GRPC service
service := NewService(
micro.Name("test.service"),
micro.Registry(r),
micro.AfterStart(func() error {
service.Name("test.service"),
service.Registry(r),
service.AfterStart(func() error {
wg.Done()
return nil
}),
micro.Context(ctx),
service.Context(ctx),
)
// register test handler
@ -81,50 +81,6 @@ func TestGRPCService(t *testing.T) {
}
}
func TestGRPCFunction(t *testing.T) {
var wg sync.WaitGroup
wg.Add(1)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// create service
fn := NewFunction(
micro.Name("test.function"),
micro.Registry(memory.NewRegistry()),
micro.AfterStart(func() error {
wg.Done()
return nil
}),
micro.Context(ctx),
)
// register test handler
hello.RegisterTestHandler(fn.Server(), &testHandler{})
// run service
go fn.Run()
// wait for start
wg.Wait()
// create client
test := hello.NewTestService("test.function", fn.Client())
// call service
rsp, err := test.Call(context.Background(), &hello.Request{
Name: "John",
})
if err != nil {
t.Fatal(err)
}
// check message
if rsp.Msg != "Hello John" {
t.Fatalf("unexpected response %s", rsp.Msg)
}
}
func TestGRPCTLSService(t *testing.T) {
var wg sync.WaitGroup
wg.Add(1)
@ -147,13 +103,13 @@ func TestGRPCTLSService(t *testing.T) {
// create GRPC service
service := NewService(
micro.Name("test.service"),
micro.Registry(r),
micro.AfterStart(func() error {
service.Name("test.service"),
service.Registry(r),
service.AfterStart(func() error {
wg.Done()
return nil
}),
micro.Context(ctx),
service.Context(ctx),
// set TLS config
WithTLS(config),
)