@@ -99,12 +99,11 @@ func (s) TestBlockingPickNoSubAvailable(t *testing.T) {
99
99
bp := newPickerWrapper (nil )
100
100
var finishedCount uint64
101
101
bp .updatePicker (& testingPicker {err : balancer .ErrNoSubConnAvailable , maxCalled : goroutineCount })
102
+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
103
+ defer cancel ()
102
104
// All goroutines should block because picker returns no subConn available.
103
105
for i := goroutineCount ; i > 0 ; i -- {
104
106
go func () {
105
- ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
106
- defer cancel ()
107
-
108
107
if tr , _ , err := bp .pick (ctx , true , balancer.PickInfo {}); err != nil || tr != testT {
109
108
t .Errorf ("bp.pick returned non-nil error: %v" , err )
110
109
}
@@ -122,13 +121,12 @@ func (s) TestBlockingPickTransientWaitforready(t *testing.T) {
122
121
bp := newPickerWrapper (nil )
123
122
bp .updatePicker (& testingPicker {err : balancer .ErrTransientFailure , maxCalled : goroutineCount })
124
123
var finishedCount uint64
124
+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
125
+ defer cancel ()
125
126
// All goroutines should block because picker returns transientFailure and
126
127
// picks are not failfast.
127
128
for i := goroutineCount ; i > 0 ; i -- {
128
129
go func () {
129
- ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
130
- defer cancel ()
131
-
132
130
if tr , _ , err := bp .pick (ctx , false , balancer.PickInfo {}); err != nil || tr != testT {
133
131
t .Errorf ("bp.pick returned non-nil error: %v" , err )
134
132
}
@@ -146,12 +144,11 @@ func (s) TestBlockingPickSCNotReady(t *testing.T) {
146
144
bp := newPickerWrapper (nil )
147
145
bp .updatePicker (& testingPicker {sc : testSCNotReady , maxCalled : goroutineCount })
148
146
var finishedCount uint64
147
+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
148
+ defer cancel ()
149
149
// All goroutines should block because subConn is not ready.
150
150
for i := goroutineCount ; i > 0 ; i -- {
151
151
go func () {
152
- ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
153
- defer cancel ()
154
-
155
152
if tr , _ , err := bp .pick (ctx , true , balancer.PickInfo {}); err != nil || tr != testT {
156
153
t .Errorf ("bp.pick returned non-nil error: %v" , err )
157
154
}
0 commit comments