@@ -12,6 +12,7 @@ import {
1212 Db ,
1313 getTopology ,
1414 MongoClient ,
15+ MongoNetworkError ,
1516 MongoNotConnectedError ,
1617 MongoServerSelectionError ,
1718 ReadPreference ,
@@ -333,6 +334,28 @@ describe('class MongoClient', function () {
333334 }
334335 } ) ;
335336 } ) ;
337+
338+ it ( 'throws ENOTFOUND error when connecting to non-existent host with no auth and loadBalanced=true' , async function ( ) {
339+ const configuration = this . configuration ;
340+ const client = configuration . newClient (
341+ 'mongodb://iLoveJavaScript:27017/test?loadBalanced=true' ,
342+ { serverSelectionTimeoutMS : 100 }
343+ ) ;
344+
345+ const error = await client . connect ( ) . catch ( error => error ) ;
346+ expect ( error ) . to . be . instanceOf ( MongoNetworkError ) ; // not server selection like other topologies
347+ expect ( error . message ) . to . match ( / E N O T F O U N D / ) ;
348+ } ) ;
349+
350+ it ( 'throws an error when srv is not a real record' , async function ( ) {
351+ const client = this . configuration . newClient ( 'mongodb+srv://iLoveJavaScript/test' , {
352+ serverSelectionTimeoutMS : 100
353+ } ) ;
354+
355+ const error = await client . connect ( ) . catch ( error => error ) ;
356+ expect ( error ) . to . be . instanceOf ( Error ) ;
357+ expect ( error . message ) . to . match ( / E N O T F O U N D / ) ;
358+ } ) ;
336359 } ) ;
337360
338361 it ( 'Should correctly pass through appname' , {
@@ -600,15 +623,17 @@ describe('class MongoClient', function () {
600623 ) ;
601624
602625 it (
603- 'does not checkout connection when authentication is disabled' ,
626+ 'checks out connection to confirm connectivity even when authentication is disabled' ,
604627 { requires : { auth : 'disabled' } } ,
605628 async function ( ) {
606629 const checkoutStartedEvents = [ ] ;
607630 client . on ( 'connectionCheckOutStarted' , event => {
608631 checkoutStartedEvents . push ( event ) ;
609632 } ) ;
633+ const checkoutStarted = once ( client , 'connectionCheckOutStarted' ) ;
610634 await client . connect ( ) ;
611- expect ( checkoutStartedEvents ) . to . be . empty ;
635+ const checkout = await checkoutStarted ;
636+ expect ( checkout ) . to . exist ;
612637 expect ( client ) . to . have . property ( 'topology' ) . that . is . instanceOf ( Topology ) ;
613638 }
614639 ) ;
0 commit comments