Skip to content

Commit

Permalink
fixup closing conns
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Witkowski committed Mar 27, 2017
1 parent a8f5f87 commit 3fcbd37
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions proxy/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ func (s *assertingService) PingStream(stream pb.TestService_PingStreamServer) er
type ProxyHappySuite struct {
suite.Suite

serverListener net.Listener
server *grpc.Server
proxyListener net.Listener
proxy *grpc.Server
serverListener net.Listener
server *grpc.Server
proxyListener net.Listener
proxy *grpc.Server
serverClientConn *grpc.ClientConn

client *grpc.ClientConn
testClient pb.TestServiceClient
Expand Down Expand Up @@ -201,7 +202,7 @@ func (s *ProxyHappySuite) SetupSuite() {
pb.RegisterTestServiceServer(s.server, &assertingService{t: s.T()})

// Setup of the proxy's Director.
proxyClientConn, err := grpc.Dial(s.serverListener.Addr().String(), grpc.WithInsecure(), grpc.WithCodec(proxy.Codec()))
s.serverClientConn, err = grpc.Dial(s.serverListener.Addr().String(), grpc.WithInsecure(), grpc.WithCodec(proxy.Codec()))
require.NoError(s.T(), err, "must not error on deferred client Dial")
director := func(ctx context.Context, fullName string) (*grpc.ClientConn, error) {
md, ok := metadata.FromContext(ctx)
Expand All @@ -210,7 +211,7 @@ func (s *ProxyHappySuite) SetupSuite() {
return nil, grpc.Errorf(codes.PermissionDenied, "testing rejection")
}
}
return proxyClientConn, nil
return s.serverClientConn, nil
}
s.proxy = grpc.NewServer(
grpc.CustomCodec(proxy.Codec()),
Expand All @@ -237,6 +238,14 @@ func (s *ProxyHappySuite) SetupSuite() {
}

func (s *ProxyHappySuite) TearDownSuite() {
if s.client != nil {
s.client.Close()
}
if s.serverClientConn != nil {
s.serverClientConn.Close()
}
// Close all transports so the logs don't get spammy.
time.Sleep(10 * time.Millisecond)
if s.proxy != nil {
s.proxy.Stop()
s.proxyListener.Close()
Expand All @@ -245,9 +254,6 @@ func (s *ProxyHappySuite) TearDownSuite() {
s.server.Stop()
s.serverListener.Close()
}
if s.client != nil {
s.client.Close()
}
}

func TestProxyHappySuite(t *testing.T) {
Expand Down

0 comments on commit 3fcbd37

Please sign in to comment.