Serve() should not return error on Stop() or GracefulStop() (#1485)
* Serve() should not return error on Stop() or GracefulStop() * Block Serve() until Stop() or GracefulStop() returns
This commit is contained in:

committed by
Menghan Li

parent
faebfcb7bf
commit
473b14250d
@ -23,6 +23,7 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc/test/leakcheck"
|
||||
)
|
||||
@ -53,6 +54,27 @@ func TestStopBeforeServe(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGracefulStop(t *testing.T) {
|
||||
defer leakcheck.Check(t)
|
||||
|
||||
lis, err := net.Listen("tcp", "localhost:0")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create listener: %v", err)
|
||||
}
|
||||
|
||||
server := NewServer()
|
||||
go func() {
|
||||
// make sure Serve() is called
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
server.GracefulStop()
|
||||
}()
|
||||
|
||||
err = server.Serve(lis)
|
||||
if err != nil {
|
||||
t.Fatalf("Serve() returned non-nil error on GracefulStop: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetServiceInfo(t *testing.T) {
|
||||
defer leakcheck.Check(t)
|
||||
testSd := ServiceDesc{
|
||||
|
Reference in New Issue
Block a user