Skip to content

Commit dfe089c

Browse files
committed
Refactor: defer ctx cancel() calls
1 parent c2a2f88 commit dfe089c

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

interop/client/client.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ func main() {
269269
tc := testgrpc.NewTestServiceClient(conn)
270270
overallDeadline := time.Now().Add(time.Duration(*soakOverallTimeoutSeconds) * time.Second)
271271
ctxWithDeadline, cancel := context.WithDeadline(ctx, overallDeadline)
272+
defer cancel()
272273
switch *testCase {
273274
case "empty_unary":
274275
interop.DoEmptyUnaryCall(ctx, tc)
@@ -359,11 +360,9 @@ func main() {
359360
logger.Infoln("PickFirstUnary done")
360361
case "rpc_soak":
361362
interop.DoSoakTest(ctxWithDeadline, tc, serverAddr, opts, false /* resetChannel */, *soakIterations, *soakMaxFailures, *soakRequestSize, *soakResponseSize, time.Duration(*soakPerIterationMaxAcceptableLatencyMs)*time.Millisecond, time.Duration(*soakMinTimeMsBetweenRPCs)*time.Millisecond)
362-
cancel()
363363
logger.Infoln("RpcSoak done")
364364
case "channel_soak":
365365
interop.DoSoakTest(ctxWithDeadline, tc, serverAddr, opts, true /* resetChannel */, *soakIterations, *soakMaxFailures, *soakRequestSize, *soakResponseSize, time.Duration(*soakPerIterationMaxAcceptableLatencyMs)*time.Millisecond, time.Duration(*soakMinTimeMsBetweenRPCs)*time.Millisecond)
366-
cancel()
367366
logger.Infoln("ChannelSoak done")
368367
case "orca_per_rpc":
369368
interop.DoORCAPerRPCTest(ctx, tc)

interop/xds_federation/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ func main() {
122122
go func(c clientConfig) {
123123
overallDeadline := time.Now().Add(time.Duration(*soakOverallTimeoutSeconds) * time.Second)
124124
ctxWithDeadline, cancel := context.WithDeadline(ctx, overallDeadline)
125+
defer cancel()
125126
interop.DoSoakTest(ctxWithDeadline, c.tc, c.uri, c.opts, resetChannel, *soakIterations, *soakMaxFailures, *soakRequestSize, *soakResponseSize, time.Duration(*soakPerIterationMaxAcceptableLatencyMs)*time.Millisecond, time.Duration(*soakMinTimeMsBetweenRPCs)*time.Millisecond)
126-
cancel()
127127
logger.Infof("%s test done for server: %s", *testCase, c.uri)
128128
wg.Done()
129129
}(clients[i])

0 commit comments

Comments
 (0)