Skip to content

Commit 132187f

Browse files
Modified tests to use tlogger. (grpc#3343)
* Modified tests to use tlogger. * Fail on errors, with error expectations. * Added expects and MixedCapsed grpclb_config tests * Moved tlogger to grpctest, moved leakcheck tester to grpctest.go * Added ExpectErrorN() * Removed redundant leak checks * Fixed new test * Made tlogger globals into tlogger methods * ErrorsLeft -> EndTest * Removed some redundant lines * Fixed error in test and empty map in EndTest
1 parent cb03b9f commit 132187f

File tree

77 files changed

+1036
-614
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1036
-614
lines changed

balancer/grpclb/grpclb_config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"google.golang.org/grpc/serviceconfig"
3030
)
3131

32-
func Test_Parse(t *testing.T) {
32+
func (s) TestParse(t *testing.T) {
3333
tests := []struct {
3434
name string
3535
s string
@@ -71,7 +71,7 @@ func Test_Parse(t *testing.T) {
7171
}
7272
}
7373

74-
func Test_childIsPickFirst(t *testing.T) {
74+
func (s) TestChildIsPickFirst(t *testing.T) {
7575
tests := []struct {
7676
name string
7777
s string

balancer/grpclb/grpclb_test.go

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
"google.golang.org/grpc/codes"
4040
"google.golang.org/grpc/credentials"
4141
_ "google.golang.org/grpc/grpclog/glogger"
42-
"google.golang.org/grpc/internal/leakcheck"
42+
"google.golang.org/grpc/internal/grpctest"
4343
"google.golang.org/grpc/metadata"
4444
"google.golang.org/grpc/peer"
4545
"google.golang.org/grpc/resolver"
@@ -59,6 +59,14 @@ var (
5959
fakeName = "fake.Name"
6060
)
6161

62+
type s struct {
63+
grpctest.Tester
64+
}
65+
66+
func Test(t *testing.T) {
67+
grpctest.RunSubTests(t, s{})
68+
}
69+
6270
type serverNameCheckCreds struct {
6371
mu sync.Mutex
6472
sn string
@@ -383,9 +391,7 @@ func newLoadBalancer(numberOfBackends int, statsChan chan *lbpb.ClientStats) (ts
383391
return
384392
}
385393

386-
func TestGRPCLB(t *testing.T) {
387-
defer leakcheck.Check(t)
388-
394+
func (s) TestGRPCLB(t *testing.T) {
389395
r, cleanup := manual.GenerateAndRegisterManualResolver()
390396
defer cleanup()
391397

@@ -429,9 +435,7 @@ func TestGRPCLB(t *testing.T) {
429435
}
430436

431437
// The remote balancer sends response with duplicates to grpclb client.
432-
func TestGRPCLBWeighted(t *testing.T) {
433-
defer leakcheck.Check(t)
434-
438+
func (s) TestGRPCLBWeighted(t *testing.T) {
435439
r, cleanup := manual.GenerateAndRegisterManualResolver()
436440
defer cleanup()
437441

@@ -497,9 +501,7 @@ func TestGRPCLBWeighted(t *testing.T) {
497501
}
498502
}
499503

500-
func TestDropRequest(t *testing.T) {
501-
defer leakcheck.Check(t)
502-
504+
func (s) TestDropRequest(t *testing.T) {
503505
r, cleanup := manual.GenerateAndRegisterManualResolver()
504506
defer cleanup()
505507

@@ -650,9 +652,7 @@ func TestDropRequest(t *testing.T) {
650652
}
651653

652654
// When the balancer in use disconnects, grpclb should connect to the next address from resolved balancer address list.
653-
func TestBalancerDisconnects(t *testing.T) {
654-
defer leakcheck.Check(t)
655-
655+
func (s) TestBalancerDisconnects(t *testing.T) {
656656
r, cleanup := manual.GenerateAndRegisterManualResolver()
657657
defer cleanup()
658658

@@ -727,12 +727,10 @@ func TestBalancerDisconnects(t *testing.T) {
727727
t.Fatalf("No RPC sent to second backend after 1 second")
728728
}
729729

730-
func TestFallback(t *testing.T) {
730+
func (s) TestFallback(t *testing.T) {
731731
balancer.Register(newLBBuilderWithFallbackTimeout(100 * time.Millisecond))
732732
defer balancer.Register(newLBBuilder())
733733

734-
defer leakcheck.Check(t)
735-
736734
r, cleanup := manual.GenerateAndRegisterManualResolver()
737735
defer cleanup()
738736

@@ -860,9 +858,7 @@ func TestFallback(t *testing.T) {
860858
}
861859
}
862860

863-
func TestExplicitFallback(t *testing.T) {
864-
defer leakcheck.Check(t)
865-
861+
func (s) TestExplicitFallback(t *testing.T) {
866862
r, cleanup := manual.GenerateAndRegisterManualResolver()
867863
defer cleanup()
868864

@@ -965,9 +961,7 @@ func TestExplicitFallback(t *testing.T) {
965961
}
966962
}
967963

968-
func TestFallBackWithNoServerAddress(t *testing.T) {
969-
defer leakcheck.Check(t)
970-
964+
func (s) TestFallBackWithNoServerAddress(t *testing.T) {
971965
resolveNowCh := make(chan struct{}, 1)
972966
r, cleanup := manual.GenerateAndRegisterManualResolver()
973967
r.ResolveNowCallback = func(resolver.ResolveNowOptions) {
@@ -1087,9 +1081,7 @@ func TestFallBackWithNoServerAddress(t *testing.T) {
10871081
}
10881082
}
10891083

1090-
func TestGRPCLBPickFirst(t *testing.T) {
1091-
defer leakcheck.Check(t)
1092-
1084+
func (s) TestGRPCLBPickFirst(t *testing.T) {
10931085
r, cleanup := manual.GenerateAndRegisterManualResolver()
10941086
defer cleanup()
10951087

@@ -1301,8 +1293,7 @@ const (
13011293
failtosendURI = "failtosend"
13021294
)
13031295

1304-
func TestGRPCLBStatsUnarySuccess(t *testing.T) {
1305-
defer leakcheck.Check(t)
1296+
func (s) TestGRPCLBStatsUnarySuccess(t *testing.T) {
13061297
if err := runAndCheckStats(t, false, nil, func(cc *grpc.ClientConn) {
13071298
testC := testpb.NewTestServiceClient(cc)
13081299
// The first non-failfast RPC succeeds, all connections are up.
@@ -1321,8 +1312,7 @@ func TestGRPCLBStatsUnarySuccess(t *testing.T) {
13211312
}
13221313
}
13231314

1324-
func TestGRPCLBStatsUnaryDrop(t *testing.T) {
1325-
defer leakcheck.Check(t)
1315+
func (s) TestGRPCLBStatsUnaryDrop(t *testing.T) {
13261316
if err := runAndCheckStats(t, true, nil, func(cc *grpc.ClientConn) {
13271317
testC := testpb.NewTestServiceClient(cc)
13281318
// The first non-failfast RPC succeeds, all connections are up.
@@ -1342,8 +1332,7 @@ func TestGRPCLBStatsUnaryDrop(t *testing.T) {
13421332
}
13431333
}
13441334

1345-
func TestGRPCLBStatsUnaryFailedToSend(t *testing.T) {
1346-
defer leakcheck.Check(t)
1335+
func (s) TestGRPCLBStatsUnaryFailedToSend(t *testing.T) {
13471336
if err := runAndCheckStats(t, false, nil, func(cc *grpc.ClientConn) {
13481337
testC := testpb.NewTestServiceClient(cc)
13491338
// The first non-failfast RPC succeeds, all connections are up.
@@ -1363,8 +1352,7 @@ func TestGRPCLBStatsUnaryFailedToSend(t *testing.T) {
13631352
}
13641353
}
13651354

1366-
func TestGRPCLBStatsStreamingSuccess(t *testing.T) {
1367-
defer leakcheck.Check(t)
1355+
func (s) TestGRPCLBStatsStreamingSuccess(t *testing.T) {
13681356
if err := runAndCheckStats(t, false, nil, func(cc *grpc.ClientConn) {
13691357
testC := testpb.NewTestServiceClient(cc)
13701358
// The first non-failfast RPC succeeds, all connections are up.
@@ -1397,8 +1385,7 @@ func TestGRPCLBStatsStreamingSuccess(t *testing.T) {
13971385
}
13981386
}
13991387

1400-
func TestGRPCLBStatsStreamingDrop(t *testing.T) {
1401-
defer leakcheck.Check(t)
1388+
func (s) TestGRPCLBStatsStreamingDrop(t *testing.T) {
14021389
if err := runAndCheckStats(t, true, nil, func(cc *grpc.ClientConn) {
14031390
testC := testpb.NewTestServiceClient(cc)
14041391
// The first non-failfast RPC succeeds, all connections are up.
@@ -1432,8 +1419,7 @@ func TestGRPCLBStatsStreamingDrop(t *testing.T) {
14321419
}
14331420
}
14341421

1435-
func TestGRPCLBStatsStreamingFailedToSend(t *testing.T) {
1436-
defer leakcheck.Check(t)
1422+
func (s) TestGRPCLBStatsStreamingFailedToSend(t *testing.T) {
14371423
if err := runAndCheckStats(t, false, nil, func(cc *grpc.ClientConn) {
14381424
testC := testpb.NewTestServiceClient(cc)
14391425
// The first non-failfast RPC succeeds, all connections are up.
@@ -1459,8 +1445,7 @@ func TestGRPCLBStatsStreamingFailedToSend(t *testing.T) {
14591445
}
14601446
}
14611447

1462-
func TestGRPCLBStatsQuashEmpty(t *testing.T) {
1463-
defer leakcheck.Check(t)
1448+
func (s) TestGRPCLBStatsQuashEmpty(t *testing.T) {
14641449
ch := make(chan *lbpb.ClientStats)
14651450
defer close(ch)
14661451
if err := runAndCheckStats(t, false, ch, func(cc *grpc.ClientConn) {

balancer/grpclb/grpclb_util_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func checkCacheCC(ccc *lbCacheClientConn, sccLen, sctaLen int) error {
8383
}
8484

8585
// Test that SubConn won't be immediately removed.
86-
func TestLBCacheClientConnExpire(t *testing.T) {
86+
func (s) TestLBCacheClientConnExpire(t *testing.T) {
8787
mcc := newMockClientConn()
8888
if err := checkMockCC(mcc, 0); err != nil {
8989
t.Fatal(err)
@@ -135,7 +135,7 @@ func TestLBCacheClientConnExpire(t *testing.T) {
135135

136136
// Test that NewSubConn with the same address of a SubConn being removed will
137137
// reuse the SubConn and cancel the removing.
138-
func TestLBCacheClientConnReuse(t *testing.T) {
138+
func (s) TestLBCacheClientConnReuse(t *testing.T) {
139139
mcc := newMockClientConn()
140140
if err := checkMockCC(mcc, 0); err != nil {
141141
t.Fatal(err)
@@ -220,7 +220,7 @@ func TestLBCacheClientConnReuse(t *testing.T) {
220220

221221
// Test that if the timer to remove a SubConn fires at the same time NewSubConn
222222
// cancels the timer, it doesn't cause deadlock.
223-
func TestLBCache_RemoveTimer_New_Race(t *testing.T) {
223+
func (s) TestLBCache_RemoveTimer_New_Race(t *testing.T) {
224224
mcc := newMockClientConn()
225225
if err := checkMockCC(mcc, 0); err != nil {
226226
t.Fatal(err)

balancer/roundrobin/roundrobin_test.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,22 @@ import (
3232
"google.golang.org/grpc/codes"
3333
"google.golang.org/grpc/connectivity"
3434
_ "google.golang.org/grpc/grpclog/glogger"
35-
"google.golang.org/grpc/internal/leakcheck"
35+
"google.golang.org/grpc/internal/grpctest"
3636
"google.golang.org/grpc/peer"
3737
"google.golang.org/grpc/resolver"
3838
"google.golang.org/grpc/resolver/manual"
3939
"google.golang.org/grpc/status"
4040
testpb "google.golang.org/grpc/test/grpc_testing"
4141
)
4242

43+
type s struct {
44+
grpctest.Tester
45+
}
46+
47+
func Test(t *testing.T) {
48+
grpctest.RunSubTests(t, s{})
49+
}
50+
4351
type testServer struct {
4452
testpb.UnimplementedTestServiceServer
4553
}
@@ -90,8 +98,7 @@ func startTestServers(count int) (_ *test, err error) {
9098
return t, nil
9199
}
92100

93-
func TestOneBackend(t *testing.T) {
94-
defer leakcheck.Check(t)
101+
func (s) TestOneBackend(t *testing.T) {
95102
r, cleanup := manual.GenerateAndRegisterManualResolver()
96103
defer cleanup()
97104

@@ -121,8 +128,7 @@ func TestOneBackend(t *testing.T) {
121128
}
122129
}
123130

124-
func TestBackendsRoundRobin(t *testing.T) {
125-
defer leakcheck.Check(t)
131+
func (s) TestBackendsRoundRobin(t *testing.T) {
126132
r, cleanup := manual.GenerateAndRegisterManualResolver()
127133
defer cleanup()
128134

@@ -181,8 +187,7 @@ func TestBackendsRoundRobin(t *testing.T) {
181187
}
182188
}
183189

184-
func TestAddressesRemoved(t *testing.T) {
185-
defer leakcheck.Check(t)
190+
func (s) TestAddressesRemoved(t *testing.T) {
186191
r, cleanup := manual.GenerateAndRegisterManualResolver()
187192
defer cleanup()
188193

@@ -239,8 +244,7 @@ func TestAddressesRemoved(t *testing.T) {
239244

240245
}
241246

242-
func TestCloseWithPendingRPC(t *testing.T) {
243-
defer leakcheck.Check(t)
247+
func (s) TestCloseWithPendingRPC(t *testing.T) {
244248
r, cleanup := manual.GenerateAndRegisterManualResolver()
245249
defer cleanup()
246250

@@ -273,8 +277,7 @@ func TestCloseWithPendingRPC(t *testing.T) {
273277
wg.Wait()
274278
}
275279

276-
func TestNewAddressWhileBlocking(t *testing.T) {
277-
defer leakcheck.Check(t)
280+
func (s) TestNewAddressWhileBlocking(t *testing.T) {
278281
r, cleanup := manual.GenerateAndRegisterManualResolver()
279282
defer cleanup()
280283

@@ -321,8 +324,7 @@ func TestNewAddressWhileBlocking(t *testing.T) {
321324
wg.Wait()
322325
}
323326

324-
func TestOneServerDown(t *testing.T) {
325-
defer leakcheck.Check(t)
327+
func (s) TestOneServerDown(t *testing.T) {
326328
r, cleanup := manual.GenerateAndRegisterManualResolver()
327329
defer cleanup()
328330

@@ -419,8 +421,7 @@ func TestOneServerDown(t *testing.T) {
419421
}
420422
}
421423

422-
func TestAllServersDown(t *testing.T) {
423-
defer leakcheck.Check(t)
424+
func (s) TestAllServersDown(t *testing.T) {
424425
r, cleanup := manual.GenerateAndRegisterManualResolver()
425426
defer cleanup()
426427

benchmark/flags/flags_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,19 @@ import (
2323
"reflect"
2424
"testing"
2525
"time"
26+
27+
"google.golang.org/grpc/internal/grpctest"
2628
)
2729

28-
func TestStringWithAllowedValues(t *testing.T) {
30+
type s struct {
31+
grpctest.Tester
32+
}
33+
34+
func Test(t *testing.T) {
35+
grpctest.RunSubTests(t, s{})
36+
}
37+
38+
func (s) TestStringWithAllowedValues(t *testing.T) {
2939
const defaultVal = "default"
3040
tests := []struct {
3141
args string
@@ -54,7 +64,7 @@ func TestStringWithAllowedValues(t *testing.T) {
5464
}
5565
}
5666

57-
func TestDurationSlice(t *testing.T) {
67+
func (s) TestDurationSlice(t *testing.T) {
5868
defaultVal := []time.Duration{time.Second, time.Nanosecond}
5969
tests := []struct {
6070
args string
@@ -83,7 +93,7 @@ func TestDurationSlice(t *testing.T) {
8393
}
8494
}
8595

86-
func TestIntSlice(t *testing.T) {
96+
func (s) TestIntSlice(t *testing.T) {
8797
defaultVal := []int{1, 1024}
8898
tests := []struct {
8999
args string
@@ -112,7 +122,7 @@ func TestIntSlice(t *testing.T) {
112122
}
113123
}
114124

115-
func TestStringSlice(t *testing.T) {
125+
func (s) TestStringSlice(t *testing.T) {
116126
defaultVal := []string{"bar", "baz"}
117127
tests := []struct {
118128
args string

0 commit comments

Comments
 (0)