@@ -25,6 +25,7 @@ import { Topology } from '../../../src/sdam/topology';
2525import { TopologyDescription } from '../../../src/sdam/topology_description' ;
2626import { TimeoutContext } from '../../../src/timeout' ;
2727import { isHello , ns } from '../../../src/utils' ;
28+ import { ConnectionPool } from '../../mongodb' ;
2829import * as mock from '../../tools/mongodb-mock/index' ;
2930import { topologyWithPlaceholderClient } from '../../tools/utils' ;
3031
@@ -444,31 +445,23 @@ describe('Topology (unit)', function () {
444445
445446 describe ( 'selectServer()' , function ( ) {
446447 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+ ) ;
448453 const requestCheck = sinon . stub ( Server . prototype , 'requestCheck' ) ;
449454
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-
459455 sinon . stub ( Server . prototype , 'connect' ) . callsFake ( function ( ) {
460456 this . s . state = 'connected' ;
461457 this . emit ( 'connect' ) ;
462458 return ;
463459 } ) ;
464460
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+ ) ;
472465 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 / ) ;
473466 expect ( err ) . to . have . property ( 'reason' ) ;
474467 // When server is created `connect` is called on the monitor. When server selection
@@ -516,12 +509,20 @@ describe('Topology (unit)', function () {
516509 this . emit ( 'connect' ) ;
517510 } ) ;
518511
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+
519520 const toSelect = 10 ;
520521 let completed = 0 ;
521522 // methodology:
522523 // - perform 9 server selections, a few with a selector that throws an error
523524 // - 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
525526 // - make one last selection, but ensure that all selections are no longer blocked from
526527 // returning their value
527528 // - verify that 10 callbacks were called
0 commit comments