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:
Shangpeng Sun
2017-10-18 18:27:24 -04:00
committed by Menghan Li
parent faebfcb7bf
commit 473b14250d
2 changed files with 57 additions and 0 deletions

View File

@ -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{