@@ -201,7 +201,9 @@ func (s) TestPickFirstLeaf_TFPickerUpdate(t *testing.T) {
201
201
ResolverState : resolver.State {
202
202
Endpoints : []resolver.Endpoint {
203
203
{Addresses : []resolver.Address {{Addr : "1.1.1.1:1" }}},
204
+ {Addresses : []resolver.Address {{Addr : "1.1.1.1:1" }}}, // duplicate, should be ignored.
204
205
{Addresses : []resolver.Address {{Addr : "2.2.2.2:2" }}},
206
+ {Addresses : []resolver.Address {{Addr : "1.1.1.1:1" }}}, // duplicate, should be ignored.
205
207
},
206
208
},
207
209
}
@@ -213,14 +215,35 @@ func (s) TestPickFirstLeaf_TFPickerUpdate(t *testing.T) {
213
215
// once.
214
216
tfErr := fmt .Errorf ("test err: connection refused" )
215
217
sc1 := <- cc .NewSubConnCh
218
+ select {
219
+ case <- sc1 .ConnectCh :
220
+ case <- ctx .Done ():
221
+ t .Fatal ("Context timed out waiting for Connect() to be called on sc1." )
222
+ }
216
223
sc1 .UpdateState (balancer.SubConnState {ConnectivityState : connectivity .Connecting })
217
224
sc1 .UpdateState (balancer.SubConnState {ConnectivityState : connectivity .TransientFailure , ConnectionError : tfErr })
218
225
226
+ // Move the subconn back to IDLE, it should not be re-connected until the
227
+ // first pass is complete.
228
+ shortCtx , shortCancel := context .WithTimeout (ctx , defaultTestShortTimeout )
229
+ defer shortCancel ()
230
+ sc1 .UpdateState (balancer.SubConnState {ConnectivityState : connectivity .Idle })
231
+ select {
232
+ case <- sc1 .ConnectCh :
233
+ t .Fatal ("Connect() unexpectedly called on sc1." )
234
+ case <- shortCtx .Done ():
235
+ }
236
+
219
237
if err := cc .WaitForPickerWithErr (ctx , balancer .ErrNoSubConnAvailable ); err != nil {
220
238
t .Fatalf ("cc.WaitForPickerWithErr(%v) returned error: %v" , balancer .ErrNoSubConnAvailable , err )
221
239
}
222
240
223
241
sc2 := <- cc .NewSubConnCh
242
+ select {
243
+ case <- sc2 .ConnectCh :
244
+ case <- ctx .Done ():
245
+ t .Fatal ("Context timed out waiting for Connect() to be called on sc2." )
246
+ }
224
247
sc2 .UpdateState (balancer.SubConnState {ConnectivityState : connectivity .Connecting })
225
248
sc2 .UpdateState (balancer.SubConnState {ConnectivityState : connectivity .TransientFailure , ConnectionError : tfErr })
226
249
@@ -230,6 +253,29 @@ func (s) TestPickFirstLeaf_TFPickerUpdate(t *testing.T) {
230
253
231
254
// Subsequent TRANSIENT_FAILUREs should be reported only after seeing "# of SubConns"
232
255
// TRANSIENT_FAILUREs.
256
+
257
+ // Both the subconns should be connected in parallel.
258
+ select {
259
+ case <- sc1 .ConnectCh :
260
+ case <- ctx .Done ():
261
+ t .Fatal ("Context timed out waiting for Connect() to be called on sc1." )
262
+ }
263
+
264
+ shortCtx , shortCancel = context .WithTimeout (ctx , defaultTestShortTimeout )
265
+ defer shortCancel ()
266
+ select {
267
+ case <- sc2 .ConnectCh :
268
+ t .Fatal ("Connect() called on sc2 before it completed backing-off." )
269
+ case <- shortCtx .Done ():
270
+ }
271
+
272
+ sc2 .UpdateState (balancer.SubConnState {ConnectivityState : connectivity .Idle })
273
+ select {
274
+ case <- sc2 .ConnectCh :
275
+ case <- ctx .Done ():
276
+ t .Fatal ("Context timed out waiting for Connect() to be called on sc2." )
277
+ }
278
+
233
279
newTfErr := fmt .Errorf ("test err: unreachable" )
234
280
sc2 .UpdateState (balancer.SubConnState {ConnectivityState : connectivity .TransientFailure , ConnectionError : newTfErr })
235
281
select {
0 commit comments