@@ -315,8 +315,8 @@ func TestServerSelection(t *testing.T) {
315
315
t .Errorf ("Incorrect sever selected. got %s; want %s" , srvs [0 ].Addr , desc .Servers [1 ].Addr )
316
316
}
317
317
})
318
- t .Run ("no subscription in fast path " , func (t * testing.T ) {
319
- // assert that a subscription is not created if there is a server available
318
+ t .Run ("fast path does not subscribe or check timeouts " , func (t * testing.T ) {
319
+ // Assert that the server selection fast path does not create a Subscription or check for timeout errors.
320
320
topo , err := New ()
321
321
noerr (t , err )
322
322
topo .cfg .cs .HeartbeatInterval = time .Minute
@@ -335,13 +335,31 @@ func TestServerSelection(t *testing.T) {
335
335
topo .servers [srv .Addr ] = s
336
336
}
337
337
338
- // manually close subscriptions so calls to Subscribe will error
338
+ // Manually close subscriptions so calls to Subscribe will error and pass in a cancelled context to ensure the
339
+ // fast path ignores timeout errors.
339
340
topo .subscriptionsClosed = true
340
- selectedServer , err := topo .SelectServer (context .Background (), description .WriteSelector ())
341
+ ctx , cancel := context .WithCancel (context .Background ())
342
+ cancel ()
343
+ selectedServer , err := topo .SelectServer (ctx , description .WriteSelector ())
341
344
noerr (t , err )
342
345
selectedAddr := selectedServer .(* SelectedServer ).address
343
346
assert .Equal (t , primaryAddr , selectedAddr , "expected address %v, got %v" , primaryAddr , selectedAddr )
344
347
})
348
+ t .Run ("default to selecting from subscription if fast path fails" , func (t * testing.T ) {
349
+ topo , err := New ()
350
+ noerr (t , err )
351
+
352
+ topo .cfg .cs .HeartbeatInterval = time .Minute
353
+ atomic .StoreInt32 (& topo .connectionstate , connected )
354
+ desc := description.Topology {
355
+ Servers : []description.Server {},
356
+ }
357
+ topo .desc .Store (desc )
358
+
359
+ topo .subscriptionsClosed = true
360
+ _ , err = topo .SelectServer (context .Background (), description .WriteSelector ())
361
+ assert .Equal (t , ErrSubscribeAfterClosed , err , "expected error %v, got %v" , ErrSubscribeAfterClosed , err )
362
+ })
345
363
}
346
364
347
365
func TestSessionTimeout (t * testing.T ) {
0 commit comments