@@ -25,6 +25,7 @@ import { Topology } from '../../../src/sdam/topology';
25
25
import { TopologyDescription } from '../../../src/sdam/topology_description' ;
26
26
import { TimeoutContext } from '../../../src/timeout' ;
27
27
import { isHello , ns } from '../../../src/utils' ;
28
+ import { ConnectionPool } from '../../mongodb' ;
28
29
import * as mock from '../../tools/mongodb-mock/index' ;
29
30
import { topologyWithPlaceholderClient } from '../../tools/utils' ;
30
31
@@ -444,31 +445,23 @@ describe('Topology (unit)', function () {
444
445
445
446
describe ( 'selectServer()' , function ( ) {
446
447
it ( 'should schedule monitoring if no suitable server is found' , async function ( ) {
447
- const topology = topologyWithPlaceholderClient ( 'someserver:27019' , { } ) ;
448
+ const topology = topologyWithPlaceholderClient (
449
+ 'someserver:27019' ,
450
+ { } ,
451
+ { serverSelectionTimeoutMS : 10 }
452
+ ) ;
448
453
const requestCheck = sinon . stub ( Server . prototype , 'requestCheck' ) ;
449
454
450
- // satisfy the initial connect, then restore the original method
451
- const selectServer = sinon
452
- . stub ( Topology . prototype , 'selectServer' )
453
- . callsFake ( async function ( ) {
454
- const server = Array . from ( this . s . servers . values ( ) ) [ 0 ] ;
455
- selectServer . restore ( ) ;
456
- return server ;
457
- } ) ;
458
-
459
455
sinon . stub ( Server . prototype , 'connect' ) . callsFake ( function ( ) {
460
456
this . s . state = 'connected' ;
461
457
this . emit ( 'connect' ) ;
462
458
return ;
463
459
} ) ;
464
460
465
- await topology . connect ( ) ;
466
- const err = await topology
467
- . selectServer ( ReadPreference . secondary , { serverSelectionTimeoutMS : 1000 } )
468
- . then (
469
- ( ) => null ,
470
- e => e
471
- ) ;
461
+ const err = await topology . connect ( ) . then (
462
+ ( ) => null ,
463
+ e => e
464
+ ) ;
472
465
expect ( err ) . to . match ( / S e r v e r s e l e c t i o n t i m e d o u t / ) ;
473
466
expect ( err ) . to . have . property ( 'reason' ) ;
474
467
// When server is created `connect` is called on the monitor. When server selection
@@ -516,12 +509,20 @@ describe('Topology (unit)', function () {
516
509
this . emit ( 'connect' ) ;
517
510
} ) ;
518
511
512
+ sinon . stub ( ConnectionPool . prototype , 'checkOut' ) . callsFake ( async function ( ) {
513
+ return { } ;
514
+ } ) ;
515
+
516
+ sinon . stub ( ConnectionPool . prototype , 'checkIn' ) . callsFake ( function ( _ ) {
517
+ return ;
518
+ } ) ;
519
+
519
520
const toSelect = 10 ;
520
521
let completed = 0 ;
521
522
// methodology:
522
523
// - perform 9 server selections, a few with a selector that throws an error
523
524
// - ensure each selection immediately returns an empty result (gated by a boolean)
524
- // guaranteeing tha the queue will be full before the last selection
525
+ // guaranteeing that the queue will be full before the last selection
525
526
// - make one last selection, but ensure that all selections are no longer blocked from
526
527
// returning their value
527
528
// - verify that 10 callbacks were called
0 commit comments