Skip to content

Commit 33f9fa2

Browse files
authored
test: speed up two tests (#6558)
1 parent aca07ce commit 33f9fa2

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

test/channelz_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,25 +1165,32 @@ func (s) TestCZClientAndServerSocketMetricsFlowControl(t *testing.T) {
11651165
}
11661166

11671167
func (s) TestCZClientSocketMetricsKeepAlive(t *testing.T) {
1168+
const keepaliveRate = 50 * time.Millisecond
11681169
czCleanup := channelz.NewChannelzStorageForTesting()
11691170
defer czCleanupWrapper(czCleanup, t)
11701171
defer func(t time.Duration) { internal.KeepaliveMinPingTime = t }(internal.KeepaliveMinPingTime)
1171-
internal.KeepaliveMinPingTime = time.Second
1172+
internal.KeepaliveMinPingTime = keepaliveRate
11721173
e := tcpClearRREnv
11731174
te := newTest(t, e)
11741175
te.customDialOptions = append(te.customDialOptions, grpc.WithKeepaliveParams(
11751176
keepalive.ClientParameters{
1176-
Time: time.Second,
1177+
Time: keepaliveRate,
11771178
Timeout: 500 * time.Millisecond,
11781179
PermitWithoutStream: true,
11791180
}))
11801181
te.customServerOptions = append(te.customServerOptions, grpc.KeepaliveEnforcementPolicy(
11811182
keepalive.EnforcementPolicy{
1182-
MinTime: 500 * time.Millisecond,
1183+
MinTime: keepaliveRate,
11831184
PermitWithoutStream: true,
11841185
}))
11851186
te.startServer(&testServer{security: e.security})
1186-
te.clientConn() // Dial the server
1187+
cc := te.clientConn() // Dial the server
1188+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
1189+
defer cancel()
1190+
awaitState(ctx, t, cc, connectivity.Ready)
1191+
start := time.Now()
1192+
// Wait for at least two keepalives to be able to occur.
1193+
time.Sleep(2 * keepaliveRate)
11871194
defer te.tearDown()
11881195
if err := verifyResultWithDelay(func() (bool, error) {
11891196
tchan, _ := channelz.GetTopChannels(0, 0)
@@ -1208,8 +1215,9 @@ func (s) TestCZClientSocketMetricsKeepAlive(t *testing.T) {
12081215
break
12091216
}
12101217
skt := channelz.GetSocket(id)
1211-
if skt.SocketData.KeepAlivesSent != 2 {
1212-
return false, fmt.Errorf("there should be 2 KeepAlives sent, not %d", skt.SocketData.KeepAlivesSent)
1218+
want := int64(time.Since(start) / keepaliveRate)
1219+
if skt.SocketData.KeepAlivesSent != want {
1220+
return false, fmt.Errorf("there should be %v KeepAlives sent, not %d", want, skt.SocketData.KeepAlivesSent)
12131221
}
12141222
return true, nil
12151223
}); err != nil {

test/end2end_test.go

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4212,7 +4212,7 @@ func (s) TestFlowControlLogicalRace(t *testing.T) {
42124212
maxFailures = 3
42134213
)
42144214

4215-
requestCount := 10000
4215+
requestCount := 3000
42164216
if raceMode {
42174217
requestCount = 1000
42184218
}
@@ -4247,33 +4247,22 @@ func (s) TestFlowControlLogicalRace(t *testing.T) {
42474247
t.Fatalf("StreamingOutputCall; err = %q", err)
42484248
}
42494249

4250-
j := 0
4251-
loop:
4252-
for ; j < recvCount; j++ {
4253-
_, err := output.Recv()
4254-
if err != nil {
4255-
if err == io.EOF {
4256-
break loop
4257-
}
4258-
switch status.Code(err) {
4259-
case codes.DeadlineExceeded:
4260-
break loop
4261-
default:
4262-
t.Fatalf("Recv; err = %q", err)
4250+
for j := 0; j < recvCount; j++ {
4251+
if _, err := output.Recv(); err != nil {
4252+
if err == io.EOF || status.Code(err) == codes.DeadlineExceeded {
4253+
t.Errorf("got %d responses to request %d", j, i)
4254+
failures++
4255+
break
42634256
}
4257+
t.Fatalf("Recv; err = %q", err)
42644258
}
42654259
}
42664260
cancel()
4267-
<-ctx.Done()
4268-
4269-
if j < recvCount {
4270-
t.Errorf("got %d responses to request %d", j, i)
4271-
failures++
4272-
if failures >= maxFailures {
4273-
// Continue past the first failure to see if the connection is
4274-
// entirely broken, or if only a single RPC was affected
4275-
break
4276-
}
4261+
4262+
if failures >= maxFailures {
4263+
// Continue past the first failure to see if the connection is
4264+
// entirely broken, or if only a single RPC was affected
4265+
t.Fatalf("Too many failures received; aborting")
42774266
}
42784267
}
42794268
}

0 commit comments

Comments
 (0)