@@ -12,6 +12,7 @@ import {
12
12
Db ,
13
13
getTopology ,
14
14
MongoClient ,
15
+ MongoNetworkError ,
15
16
MongoNotConnectedError ,
16
17
MongoServerSelectionError ,
17
18
ReadPreference ,
@@ -333,6 +334,28 @@ describe('class MongoClient', function () {
333
334
}
334
335
} ) ;
335
336
} ) ;
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
+ } ) ;
336
359
} ) ;
337
360
338
361
it ( 'Should correctly pass through appname' , {
@@ -600,15 +623,17 @@ describe('class MongoClient', function () {
600
623
) ;
601
624
602
625
it (
603
- 'does not checkout connection when authentication is disabled' ,
626
+ 'checks out connection to confirm connectivity even when authentication is disabled' ,
604
627
{ requires : { auth : 'disabled' } } ,
605
628
async function ( ) {
606
629
const checkoutStartedEvents = [ ] ;
607
630
client . on ( 'connectionCheckOutStarted' , event => {
608
631
checkoutStartedEvents . push ( event ) ;
609
632
} ) ;
633
+ const checkoutStarted = once ( client , 'connectionCheckOutStarted' ) ;
610
634
await client . connect ( ) ;
611
- expect ( checkoutStartedEvents ) . to . be . empty ;
635
+ const checkout = await checkoutStarted ;
636
+ expect ( checkout ) . to . exist ;
612
637
expect ( client ) . to . have . property ( 'topology' ) . that . is . instanceOf ( Topology ) ;
613
638
}
614
639
) ;
0 commit comments