service/grpc: t.Fatal out of TestGRPCTLSService() goroutine

This commit is contained in:
Lars Lehtonen 2019-12-11 08:28:49 -08:00
parent 27bab29e3c
commit fd531349d7
No known key found for this signature in database
GPG Key ID: 8137D474EBCB04F2

View File

@ -162,10 +162,10 @@ func TestGRPCTLSService(t *testing.T) {
hello.RegisterTestHandler(service.Server(), &testHandler{})
// run service
errCh := make(chan error, 1)
go func() {
if err := service.Run(); err != nil {
t.Fatal(err)
}
defer close(errCh)
errCh <- service.Run()
}()
// wait for start
@ -175,13 +175,23 @@ func TestGRPCTLSService(t *testing.T) {
test := hello.NewTestService("test.service", service.Client())
// call service
rsp, err := test.Call(context.Background(), &hello.Request{
ctx2, cancel2 := context.WithTimeout(context.Background(), time.Duration(time.Second))
defer cancel2()
rsp, err := test.Call(ctx2, &hello.Request{
Name: "John",
})
if err != nil {
t.Fatal(err)
}
// check server
select {
case err := <-errCh:
t.Fatal(err)
case <-time.After(time.Second):
break
}
// check message
if rsp.Msg != "Hello John" {
t.Fatalf("unexpected response %s", rsp.Msg)