Skip to content

Commit fdca263

Browse files
committed
move context creation to outside of the loops
1 parent 4b89735 commit fdca263

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

internal/binarylog/method_logger_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,11 @@ func (s) TestLog(t *testing.T) {
335335
},
336336
},
337337
}
338+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
339+
defer cancel()
338340
for i, tc := range testCases {
339341
buf.Reset()
340342
tc.want.SequenceIdWithinCall = uint64(i + 1)
341-
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
342-
defer cancel()
343343
ml.Log(ctx, tc.config)
344344
inSink := new(binlogpb.GrpcLogEntry)
345345
if err := proto.Unmarshal(buf.Bytes()[4:], inSink); err != nil {

internal/xds/rbac/rbac_engine_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,10 +1745,10 @@ func (s) TestChainEngine(t *testing.T) {
17451745
}
17461746
// Query the created chain of RBAC Engines with different args to see
17471747
// if the chain of RBAC Engines configured as such works as intended.
1748+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
1749+
defer cancel()
17481750
for _, data := range test.rbacQueries {
17491751
func() {
1750-
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
1751-
defer cancel()
17521752
// Construct the context with three data points that have enough
17531753
// information to represent incoming RPC's. This will be how a
17541754
// user uses this API. A user will have to put MD, PeerInfo, and

peer/peer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ func TestPeerStringer(t *testing.T) {
8383
want: "Peer<nil>",
8484
},
8585
}
86+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
87+
defer cancel()
8688
for _, tc := range testCases {
8789
t.Run(tc.name, func(t *testing.T) {
88-
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
89-
defer cancel()
9090
ctx = NewContext(ctx, tc.peer)
9191

9292
p, ok := FromContext(ctx)

picker_wrapper_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ func (s) TestBlockingPick(t *testing.T) {
7878
bp := newPickerWrapper(nil)
7979
// All goroutines should block because picker is nil in bp.
8080
var finishedCount uint64
81+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
82+
defer cancel()
8183
for i := goroutineCount; i > 0; i-- {
8284
go func() {
83-
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
84-
defer cancel()
85-
8685
if tr, _, err := bp.pick(ctx, true, balancer.PickInfo{}); err != nil || tr != testT {
8786
t.Errorf("bp.pick returned non-nil error: %v", err)
8887
}

0 commit comments

Comments
 (0)