Skip to content

Commit

Permalink
test: remove funcServer and some uses of NewTestServiceService (#3867)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfawley committed Sep 9, 2020
1 parent 8630cac commit 15157e2
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 189 deletions.
26 changes: 13 additions & 13 deletions test/balancer_test.go
Expand Up @@ -150,7 +150,7 @@ func (s) TestCredsBundleFromBalancer(t *testing.T) {
te.customServerOptions = []grpc.ServerOption{
grpc.Creds(creds),
}
te.startServer(&testServer{})
te.startServer((&testServer{}).Svc())
defer te.tearDown()

cc := te.clientConn()
Expand Down Expand Up @@ -179,7 +179,7 @@ func testPickExtraMetadata(t *testing.T, e env) {
grpc.WithBalancerName(testBalancerName),
grpc.WithUserAgent(testUserAgent),
}
te.startServer(&testServer{security: e.security})
te.startServer((&testServer{security: e.security}).Svc())
defer te.tearDown()

// Set resolver to xds to trigger the extra metadata code path.
Expand Down Expand Up @@ -228,7 +228,7 @@ func testDoneInfo(t *testing.T, e env) {
grpc.WithBalancerName(testBalancerName),
}
te.userAgent = failAppUA
te.startServer(&testServer{security: e.security})
te.startServer((&testServer{security: e.security}).Svc())
defer te.tearDown()

cc := te.clientConn()
Expand Down Expand Up @@ -498,7 +498,7 @@ func (s) TestAddressAttributesInNewSubConn(t *testing.T) {
}

s := grpc.NewServer()
testpb.RegisterTestServiceService(s, testpb.NewTestServiceService(&testServer{}))
testpb.RegisterTestServiceService(s, testServer{}.Svc())
go s.Serve(lis)
defer s.Stop()
t.Logf("Started gRPC server at %s...", lis.Addr().String())
Expand Down Expand Up @@ -556,12 +556,12 @@ func (s) TestServersSwap(t *testing.T) {
t.Fatalf("Error while listening. Err: %v", err)
}
s := grpc.NewServer()
ts := &funcServer{
unaryCall: func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
ts := &testpb.TestServiceService{
UnaryCall: func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
return &testpb.SimpleResponse{Username: username}, nil
},
}
testpb.RegisterTestServiceService(s, testpb.NewTestServiceService(ts))
testpb.RegisterTestServiceService(s, ts)
go s.Serve(lis)
return lis.Addr().String(), s.Stop
}
Expand Down Expand Up @@ -616,12 +616,12 @@ func (s) TestEmptyAddrs(t *testing.T) {
s := grpc.NewServer()
defer s.Stop()
const one = "1"
ts := &funcServer{
unaryCall: func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
ts := &testpb.TestServiceService{
UnaryCall: func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
return &testpb.SimpleResponse{Username: one}, nil
},
}
testpb.RegisterTestServiceService(s, testpb.NewTestServiceService(ts))
testpb.RegisterTestServiceService(s, ts)
go s.Serve(lis)

// Initialize pickfirst client
Expand Down Expand Up @@ -705,12 +705,12 @@ func (s) TestWaitForReady(t *testing.T) {
s := grpc.NewServer()
defer s.Stop()
const one = "1"
ts := &funcServer{
unaryCall: func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
ts := &testpb.TestServiceService{
UnaryCall: func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
return &testpb.SimpleResponse{Username: one}, nil
},
}
testpb.RegisterTestServiceService(s, testpb.NewTestServiceService(ts))
testpb.RegisterTestServiceService(s, ts)
go s.Serve(lis)

// Initialize client
Expand Down
2 changes: 1 addition & 1 deletion test/channelz_linux_go110_test.go
Expand Up @@ -43,7 +43,7 @@ func testCZSocketMetricsSocketOption(t *testing.T, e env) {
czCleanup := channelz.NewChannelzStorage()
defer czCleanupWrapper(czCleanup, t)
te := newTest(t, e)
te.startServer(&testServer{security: e.security})
te.startServer((&testServer{security: e.security}).Svc())
defer te.tearDown()
cc := te.clientConn()
tc := testpb.NewTestServiceClient(cc)
Expand Down
40 changes: 20 additions & 20 deletions test/channelz_test.go
Expand Up @@ -85,7 +85,7 @@ func (s) TestCZServerRegistrationAndDeletion(t *testing.T) {
defer czCleanupWrapper(czCleanup, t)
e := tcpClearRREnv
te := newTest(t, e)
te.startServers(&testServer{security: e.security}, c.total)
te.startServers(testServer{security: e.security}.Svc(), c.total)

ss, end := channelz.GetServers(c.start, c.max)
if int64(len(ss)) != c.length || end != c.end {
Expand All @@ -104,7 +104,7 @@ func (s) TestCZGetServer(t *testing.T) {
defer czCleanupWrapper(czCleanup, t)
e := tcpClearRREnv
te := newTest(t, e)
te.startServer(&testServer{security: e.security})
te.startServer(testServer{security: e.security}.Svc())
defer te.tearDown()

ss, _ := channelz.GetServers(0, 0)
Expand Down Expand Up @@ -253,7 +253,7 @@ func (s) TestCZClientSubChannelSocketRegistrationAndDeletion(t *testing.T) {
num := 3 // number of backends
te := newTest(t, e)
var svrAddrs []resolver.Address
te.startServers(&testServer{security: e.security}, num)
te.startServers(testServer{security: e.security}.Svc(), num)
r := manual.NewBuilderWithScheme("whatever")
for _, a := range te.srvAddrs {
svrAddrs = append(svrAddrs, resolver.Address{Addr: a})
Expand Down Expand Up @@ -339,7 +339,7 @@ func (s) TestCZServerSocketRegistrationAndDeletion(t *testing.T) {
defer czCleanupWrapper(czCleanup, t)
e := tcpClearRREnv
te := newTest(t, e)
te.startServer(&testServer{security: e.security})
te.startServer(testServer{security: e.security}.Svc())
var ccs []*grpc.ClientConn
for i := 0; i < c.total; i++ {
cc := te.clientConn()
Expand Down Expand Up @@ -504,7 +504,7 @@ func (s) TestCZChannelMetrics(t *testing.T) {
te := newTest(t, e)
te.maxClientSendMsgSize = newInt(8)
var svrAddrs []resolver.Address
te.startServers(&testServer{security: e.security}, num)
te.startServers(testServer{security: e.security}.Svc(), num)
r := manual.NewBuilderWithScheme("whatever")
for _, a := range te.srvAddrs {
svrAddrs = append(svrAddrs, resolver.Address{Addr: a})
Expand Down Expand Up @@ -590,7 +590,7 @@ func (s) TestCZServerMetrics(t *testing.T) {
e := tcpClearRREnv
te := newTest(t, e)
te.maxServerReceiveMsgSize = newInt(8)
te.startServer(&testServer{security: e.security})
te.startServer(testServer{security: e.security}.Svc())
defer te.tearDown()
cc := te.clientConn()
tc := testpb.NewTestServiceClient(cc)
Expand Down Expand Up @@ -861,7 +861,7 @@ func (s) TestCZClientSocketMetricsStreamsAndMessagesCount(t *testing.T) {
te := newTest(t, e)
te.maxServerReceiveMsgSize = newInt(20)
te.maxClientReceiveMsgSize = newInt(20)
rcw := te.startServerWithConnControl(&testServer{security: e.security})
rcw := te.startServerWithConnControl(testServer{security: e.security}.Svc())
defer te.tearDown()
cc := te.clientConn()
tc := &testServiceClientWrapper{TestServiceClient: testpb.NewTestServiceClient(cc)}
Expand Down Expand Up @@ -963,7 +963,7 @@ func (s) TestCZClientAndServerSocketMetricsStreamsCountFlowControlRSTStream(t *t
// Avoid overflowing connection level flow control window, which will lead to
// transport being closed.
te.serverInitialConnWindowSize = 65536 * 2
ts := &funcServer{fullDuplexCall: func(stream testpb.TestService_FullDuplexCallServer) error {
ts := &testpb.TestServiceService{FullDuplexCall: func(stream testpb.TestService_FullDuplexCallServer) error {
stream.Send(&testpb.StreamingOutputCallResponse{})
<-stream.Context().Done()
return status.Errorf(codes.DeadlineExceeded, "deadline exceeded or cancelled")
Expand Down Expand Up @@ -1048,7 +1048,7 @@ func (s) TestCZClientAndServerSocketMetricsFlowControl(t *testing.T) {
te.serverInitialConnWindowSize = 65536
te.clientInitialWindowSize = 65536
te.clientInitialConnWindowSize = 65536
te.startServer(&testServer{security: e.security})
te.startServer(testServer{security: e.security}.Svc())
defer te.tearDown()
cc := te.clientConn()
tc := testpb.NewTestServiceClient(cc)
Expand Down Expand Up @@ -1169,7 +1169,7 @@ func (s) TestCZClientSocketMetricsKeepAlive(t *testing.T) {
MinTime: 500 * time.Millisecond,
PermitWithoutStream: true,
}))
te.startServer(&testServer{security: e.security})
te.startServer(testServer{security: e.security}.Svc())
te.clientConn() // Dial the server
defer te.tearDown()
if err := verifyResultWithDelay(func() (bool, error) {
Expand Down Expand Up @@ -1211,7 +1211,7 @@ func (s) TestCZServerSocketMetricsStreamsAndMessagesCount(t *testing.T) {
te := newTest(t, e)
te.maxServerReceiveMsgSize = newInt(20)
te.maxClientReceiveMsgSize = newInt(20)
te.startServer(&testServer{security: e.security})
te.startServer(testServer{security: e.security}.Svc())
defer te.tearDown()
cc, _ := te.clientConnWithConnControl()
tc := &testServiceClientWrapper{TestServiceClient: testpb.NewTestServiceClient(cc)}
Expand Down Expand Up @@ -1282,7 +1282,7 @@ func (s) TestCZServerSocketMetricsKeepAlive(t *testing.T) {
Timeout: 100 * time.Millisecond,
})
te.customServerOptions = append(te.customServerOptions, kpOption)
te.startServer(&testServer{security: e.security})
te.startServer(testServer{security: e.security}.Svc())
defer te.tearDown()
cc := te.clientConn()
tc := testpb.NewTestServiceClient(cc)
Expand Down Expand Up @@ -1342,7 +1342,7 @@ func (s) TestCZSocketGetSecurityValueTLS(t *testing.T) {
defer czCleanupWrapper(czCleanup, t)
e := tcpTLSRREnv
te := newTest(t, e)
te.startServer(&testServer{security: e.security})
te.startServer(testServer{security: e.security}.Svc())
defer te.tearDown()
te.clientConn()
if err := verifyResultWithDelay(func() (bool, error) {
Expand Down Expand Up @@ -1467,7 +1467,7 @@ func (s) TestCZSubChannelTraceCreationDeletion(t *testing.T) {
defer czCleanupWrapper(czCleanup, t)
e := tcpClearRREnv
te := newTest(t, e)
te.startServer(&testServer{security: e.security})
te.startServer(testServer{security: e.security}.Svc())
r := manual.NewBuilderWithScheme("whatever")
r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: te.srvAddr}}})
te.resolverScheme = r.Scheme()
Expand Down Expand Up @@ -1560,7 +1560,7 @@ func (s) TestCZChannelAddressResolutionChange(t *testing.T) {
e := tcpClearRREnv
e.balancer = ""
te := newTest(t, e)
te.startServer(&testServer{security: e.security})
te.startServer(testServer{security: e.security}.Svc())
r := manual.NewBuilderWithScheme("whatever")
addrs := []resolver.Address{{Addr: te.srvAddr}}
r.InitialState(resolver.State{Addresses: addrs})
Expand Down Expand Up @@ -1663,7 +1663,7 @@ func (s) TestCZSubChannelPickedNewAddress(t *testing.T) {
e := tcpClearRREnv
e.balancer = ""
te := newTest(t, e)
te.startServers(&testServer{security: e.security}, 3)
te.startServers(testServer{security: e.security}.Svc(), 3)
r := manual.NewBuilderWithScheme("whatever")
var svrAddrs []resolver.Address
for _, a := range te.srvAddrs {
Expand Down Expand Up @@ -1722,7 +1722,7 @@ func (s) TestCZSubChannelConnectivityState(t *testing.T) {
defer czCleanupWrapper(czCleanup, t)
e := tcpClearRREnv
te := newTest(t, e)
te.startServer(&testServer{security: e.security})
te.startServer(testServer{security: e.security}.Svc())
r := manual.NewBuilderWithScheme("whatever")
r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: te.srvAddr}}})
te.resolverScheme = r.Scheme()
Expand Down Expand Up @@ -1816,7 +1816,7 @@ func (s) TestCZChannelConnectivityState(t *testing.T) {
defer czCleanupWrapper(czCleanup, t)
e := tcpClearRREnv
te := newTest(t, e)
te.startServer(&testServer{security: e.security})
te.startServer(testServer{security: e.security}.Svc())
r := manual.NewBuilderWithScheme("whatever")
r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: te.srvAddr}}})
te.resolverScheme = r.Scheme()
Expand Down Expand Up @@ -1939,7 +1939,7 @@ func (s) TestCZTraceOverwriteSubChannelDeletion(t *testing.T) {
te := newTest(t, e)
channelz.SetMaxTraceEntry(1)
defer channelz.ResetMaxTraceEntryToDefault()
te.startServer(&testServer{security: e.security})
te.startServer(testServer{security: e.security}.Svc())
r := manual.NewBuilderWithScheme("whatever")
r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: te.srvAddr}}})
te.resolverScheme = r.Scheme()
Expand Down Expand Up @@ -1997,7 +1997,7 @@ func (s) TestCZTraceTopChannelDeletionTraceClear(t *testing.T) {
defer czCleanupWrapper(czCleanup, t)
e := tcpClearRREnv
te := newTest(t, e)
te.startServer(&testServer{security: e.security})
te.startServer(testServer{security: e.security}.Svc())
r := manual.NewBuilderWithScheme("whatever")
r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: te.srvAddr}}})
te.resolverScheme = r.Scheme()
Expand Down
20 changes: 10 additions & 10 deletions test/creds_test.go
Expand Up @@ -87,7 +87,7 @@ func (s) TestCredsBundleBoth(t *testing.T) {
te.customServerOptions = []grpc.ServerOption{
grpc.Creds(creds),
}
te.startServer(&testServer{})
te.startServer(testServer{}.Svc())
defer te.tearDown()

cc := te.clientConn()
Expand All @@ -109,7 +109,7 @@ func (s) TestCredsBundleTransportCredentials(t *testing.T) {
te.customServerOptions = []grpc.ServerOption{
grpc.Creds(creds),
}
te.startServer(&testServer{})
te.startServer(testServer{}.Svc())
defer te.tearDown()

cc := te.clientConn()
Expand All @@ -125,7 +125,7 @@ func (s) TestCredsBundlePerRPCCredentials(t *testing.T) {
te.customDialOptions = []grpc.DialOption{
grpc.WithCredentialsBundle(&testCredsBundle{t: t, mode: bundlePerRPCOnly}),
}
te.startServer(&testServer{})
te.startServer(testServer{}.Svc())
defer te.tearDown()

cc := te.clientConn()
Expand Down Expand Up @@ -159,7 +159,7 @@ func (c *clientTimeoutCreds) Clone() credentials.TransportCredentials {
func (s) TestNonFailFastRPCSucceedOnTimeoutCreds(t *testing.T) {
te := newTest(t, env{name: "timeout-cred", network: "tcp", security: "empty"})
te.userAgent = testAppUA
te.startServer(&testServer{security: te.e.security})
te.startServer(testServer{security: te.e.security}.Svc())
defer te.tearDown()

cc := te.clientConn(grpc.WithTransportCredentials(&clientTimeoutCreds{}))
Expand All @@ -183,7 +183,7 @@ func (s) TestGRPCMethodAccessibleToCredsViaContextRequestInfo(t *testing.T) {
const wantMethod = "/grpc.testing.TestService/EmptyCall"
te := newTest(t, env{name: "context-request-info", network: "tcp"})
te.userAgent = testAppUA
te.startServer(&testServer{security: te.e.security})
te.startServer(testServer{security: te.e.security}.Svc())
defer te.tearDown()

cc := te.clientConn(grpc.WithPerRPCCredentials(&methodTestCreds{}))
Expand Down Expand Up @@ -218,7 +218,7 @@ func (c clientAlwaysFailCred) Clone() credentials.TransportCredentials {

func (s) TestFailFastRPCErrorOnBadCertificates(t *testing.T) {
te := newTest(t, env{name: "bad-cred", network: "tcp", security: "empty", balancer: "round_robin"})
te.startServer(&testServer{security: te.e.security})
te.startServer(testServer{security: te.e.security}.Svc())
defer te.tearDown()

opts := []grpc.DialOption{grpc.WithTransportCredentials(clientAlwaysFailCred{})}
Expand Down Expand Up @@ -246,7 +246,7 @@ func (s) TestFailFastRPCErrorOnBadCertificates(t *testing.T) {

func (s) TestWaitForReadyRPCErrorOnBadCertificates(t *testing.T) {
te := newTest(t, env{name: "bad-cred", network: "tcp", security: "empty", balancer: "round_robin"})
te.startServer(&testServer{security: te.e.security})
te.startServer(testServer{security: te.e.security}.Svc())
defer te.tearDown()

opts := []grpc.DialOption{grpc.WithTransportCredentials(clientAlwaysFailCred{})}
Expand Down Expand Up @@ -312,7 +312,7 @@ func testPerRPCCredentialsViaDialOptions(t *testing.T, e env) {
te := newTest(t, e)
te.tapHandle = authHandle
te.perRPCCreds = testPerRPCCredentials{}
te.startServer(&testServer{security: e.security})
te.startServer(testServer{security: e.security}.Svc())
defer te.tearDown()

cc := te.clientConn()
Expand All @@ -331,7 +331,7 @@ func (s) TestPerRPCCredentialsViaCallOptions(t *testing.T) {
func testPerRPCCredentialsViaCallOptions(t *testing.T, e env) {
te := newTest(t, e)
te.tapHandle = authHandle
te.startServer(&testServer{security: e.security})
te.startServer(testServer{security: e.security}.Svc())
defer te.tearDown()

cc := te.clientConn()
Expand Down Expand Up @@ -371,7 +371,7 @@ func testPerRPCCredentialsViaDialOptionsAndCallOptions(t *testing.T, e env) {
}
return ctx, nil
}
te.startServer(&testServer{security: e.security})
te.startServer(testServer{security: e.security}.Svc())
defer te.tearDown()

cc := te.clientConn()
Expand Down

0 comments on commit 15157e2

Please sign in to comment.