@@ -18,7 +18,7 @@ import {
1818 ServerDescription ,
1919 Topology
2020} from '../../mongodb' ;
21- import { clearFailPoint , configureFailPoint , runLater } from '../../tools/utils' ;
21+ import { clearFailPoint , configureFailPoint } from '../../tools/utils' ;
2222import { setupDatabase } from '../shared' ;
2323
2424describe ( 'class MongoClient' , function ( ) {
@@ -588,30 +588,27 @@ describe('class MongoClient', function () {
588588 } ) ;
589589
590590 it (
591- 'creates topology and send ping when auth is enabled' ,
591+ 'creates topology and checks out connection when auth is enabled' ,
592592 { requires : { auth : 'enabled' } } ,
593593 async function ( ) {
594- const commandToBeStarted = once ( client , 'commandStarted ' ) ;
594+ const checkoutStarted = once ( client , 'connectionCheckOutStarted ' ) ;
595595 await client . connect ( ) ;
596- const [ pingOnConnect ] = await commandToBeStarted ;
597- expect ( pingOnConnect ) . to . have . property ( 'commandName' , 'ping' ) ;
596+ const checkout = await checkoutStarted ;
597+ expect ( checkout ) . to . exist ;
598598 expect ( client ) . to . have . property ( 'topology' ) . that . is . instanceOf ( Topology ) ;
599599 }
600600 ) ;
601601
602602 it (
603- 'does not send ping when authentication is disabled' ,
603+ 'does not checkout connection when authentication is disabled' ,
604604 { requires : { auth : 'disabled' } } ,
605605 async function ( ) {
606- const commandToBeStarted = once ( client , 'commandStarted' ) ;
606+ const checkoutStartedEvents = [ ] ;
607+ client . on ( 'connectionCheckOutStarted' , event => {
608+ checkoutStartedEvents . push ( event ) ;
609+ } ) ;
607610 await client . connect ( ) ;
608- const delayedFind = runLater ( async ( ) => {
609- await client . db ( ) . collection ( 'test' ) . findOne ( ) ;
610- } , 300 ) ;
611- const [ findOneOperation ] = await commandToBeStarted ;
612- // Proves that the first command started event that is emitted is a find and not a ping
613- expect ( findOneOperation ) . to . have . property ( 'commandName' , 'find' ) ;
614- await delayedFind ;
611+ expect ( checkoutStartedEvents ) . to . be . empty ;
615612 expect ( client ) . to . have . property ( 'topology' ) . that . is . instanceOf ( Topology ) ;
616613 }
617614 ) ;
@@ -620,15 +617,15 @@ describe('class MongoClient', function () {
620617 'permits operations to be run after connect is called' ,
621618 { requires : { auth : 'enabled' } } ,
622619 async function ( ) {
623- const pingCommandToBeStarted = once ( client , 'commandStarted ' ) ;
620+ const checkoutStarted = once ( client , 'connectionCheckOutStarted ' ) ;
624621 await client . connect ( ) ;
625- const [ pingOnConnect ] = await pingCommandToBeStarted ;
622+ const checkout = await checkoutStarted ;
623+ expect ( checkout ) . to . exist ;
626624
627625 const findCommandToBeStarted = once ( client , 'commandStarted' ) ;
628626 await client . db ( 'test' ) . collection ( 'test' ) . findOne ( ) ;
629627 const [ findCommandStarted ] = await findCommandToBeStarted ;
630628
631- expect ( pingOnConnect ) . to . have . property ( 'commandName' , 'ping' ) ;
632629 expect ( findCommandStarted ) . to . have . property ( 'commandName' , 'find' ) ;
633630 expect ( client ) . to . have . property ( 'topology' ) . that . is . instanceOf ( Topology ) ;
634631 }
@@ -1186,24 +1183,28 @@ describe('class MongoClient', function () {
11861183
11871184 const tests = [
11881185 // only skipInitialPing=true will have no events upon connect
1189- { description : 'should skip ping command when set to true' , value : true , expectEvents : 0 } ,
11901186 {
1191- description : 'should not skip ping command when set to false' ,
1187+ description : 'should skip connection checkout when set to true' ,
1188+ value : true ,
1189+ expectEvents : 0
1190+ } ,
1191+ {
1192+ description : 'should not skip connection checkout when set to false' ,
11921193 value : false ,
11931194 expectEvents : 1
11941195 } ,
11951196 {
1196- description : 'should not skip ping command when unset' ,
1197+ description : 'should not skip connection checkout command when unset' ,
11971198 value : undefined ,
11981199 expectEvents : 1
11991200 }
12001201 ] ;
12011202 for ( const { description, value, expectEvents } of tests ) {
12021203 it ( description , async function ( ) {
12031204 const options = value === undefined ? { } : { __skipPingOnConnect : value } ;
1204- const client = this . configuration . newClient ( { } , { ...options , monitorCommands : true } ) ;
1205+ const client = this . configuration . newClient ( { } , { ...options } ) ;
12051206 const events = [ ] ;
1206- client . on ( 'commandStarted ' , event => events . push ( event ) ) ;
1207+ client . on ( 'connectionCheckOutStarted ' , event => events . push ( event ) ) ;
12071208
12081209 try {
12091210 await client . connect ( ) ;
@@ -1212,11 +1213,6 @@ describe('class MongoClient', function () {
12121213 }
12131214
12141215 expect ( events ) . to . have . lengthOf ( expectEvents ) ;
1215- if ( expectEvents > 1 ) {
1216- for ( const event of events ) {
1217- expect ( event ) . to . have . property ( 'commandName' , 'ping' ) ;
1218- }
1219- }
12201216 } ) ;
12211217 }
12221218 } ) ;
0 commit comments