@@ -435,5 +435,78 @@ describe('server selection', function () {
435435 } ) ;
436436 } ) ;
437437 } ) ;
438+
439+ context ( 'localThresholdMS is respected as an option' , function ( ) {
440+ let serverDescription1 , serverDescription2 , serverDescription3 , serverDescriptions ;
441+ beforeEach ( ( ) => {
442+ serverDescription1 = new ServerDescription (
443+ '127.0.0.1:27017' ,
444+ {
445+ setName : 'test' ,
446+ isWritablePrimary : true ,
447+ ok : 1
448+ } ,
449+ { roundTripTime : 15 }
450+ ) ;
451+ serverDescription2 = new ServerDescription (
452+ '127.0.0.1:27018' ,
453+ {
454+ setName : 'test' ,
455+ secondary : true ,
456+ ok : 1
457+ } ,
458+ { roundTripTime : 25 }
459+ ) ;
460+ serverDescription3 = new ServerDescription (
461+ '127.0.0.1:27019' ,
462+ {
463+ setName : 'test' ,
464+ secondary : true ,
465+ ok : 1
466+ } ,
467+ { roundTripTime : 35 }
468+ ) ;
469+ serverDescriptions = new Map ( ) ;
470+ serverDescriptions . set ( serverDescription1 . address , serverDescription1 ) ;
471+ serverDescriptions . set ( serverDescription2 . address , serverDescription2 ) ;
472+ serverDescriptions . set ( serverDescription3 . address , serverDescription3 ) ;
473+ } ) ;
474+ it ( 'includes servers inside the latency window with default localThresholdMS' , function ( ) {
475+ const topologyDescription = new TopologyDescription (
476+ TopologyType . Single ,
477+ serverDescriptions ,
478+ 'test' ,
479+ MIN_SECONDARY_WRITE_WIRE_VERSION ,
480+ new ObjectId ( ) ,
481+ MIN_SECONDARY_WRITE_WIRE_VERSION
482+ ) ;
483+ const selector = secondaryWritableServerSelector ( ) ;
484+ const servers = selector ( topologyDescription , Array . from ( serverDescriptions . values ( ) ) ) ;
485+ expect ( servers ) . to . have . lengthOf ( 2 ) ;
486+ const selectedAddresses = new Set ( servers . map ( ( { address } ) => address ) ) ;
487+ expect ( selectedAddresses . has ( serverDescription1 . address ) ) . to . be . true ;
488+ expect ( selectedAddresses . has ( serverDescription2 . address ) ) . to . be . true ;
489+ expect ( selectedAddresses . has ( serverDescription3 . address ) ) . to . be . false ;
490+ } ) ;
491+
492+ it ( 'includes servers inside the latency window with custom localThresholdMS' , function ( ) {
493+ const topologyDescription = new TopologyDescription (
494+ TopologyType . Single ,
495+ serverDescriptions ,
496+ 'test' ,
497+ MIN_SECONDARY_WRITE_WIRE_VERSION ,
498+ new ObjectId ( ) ,
499+ MIN_SECONDARY_WRITE_WIRE_VERSION ,
500+ { localThresholdMS : 5 }
501+ ) ;
502+ const selector = secondaryWritableServerSelector ( ) ;
503+ const servers = selector ( topologyDescription , Array . from ( serverDescriptions . values ( ) ) ) ;
504+ expect ( servers ) . to . have . lengthOf ( 1 ) ;
505+ const selectedAddresses = new Set ( servers . map ( ( { address } ) => address ) ) ;
506+ expect ( selectedAddresses . has ( serverDescription1 . address ) ) . to . be . true ;
507+ expect ( selectedAddresses . has ( serverDescription2 . address ) ) . to . be . false ;
508+ expect ( selectedAddresses . has ( serverDescription3 . address ) ) . to . be . false ;
509+ } ) ;
510+ } ) ;
438511 } ) ;
439512} ) ;
0 commit comments