@@ -3,16 +3,15 @@ import { MongoClient as LegacyMongoClient } from 'mongodb-legacy';
3
3
4
4
import {
5
5
type CommandStartedEvent ,
6
- type CommandSucceededEvent ,
7
- LEGACY_HELLO_COMMAND ,
8
- type MongoClient ,
9
- MongoServerError
10
- } from '../../mongodb ' ;
6
+ type CommandSucceededEvent
7
+ } from '../../../src/cmap/command_monitoring_events' ;
8
+ import { LEGACY_HELLO_COMMAND } from '../../../src/constants' ;
9
+ import { MongoServerError } from '../../../src/error' ;
10
+ import { type MongoClient } from '../../../src/mongo_client ' ;
11
11
import type { TestConfiguration } from '../../tools/runner/config' ;
12
12
import { setupDatabase } from '../shared' ;
13
13
14
14
const ignoredCommands = [ LEGACY_HELLO_COMMAND ] ;
15
- let hasInitialPingOccurred = false ;
16
15
const test : {
17
16
client : MongoClient ;
18
17
commands : { started : CommandStartedEvent [ ] ; succeeded : CommandSucceededEvent [ ] } ;
@@ -24,16 +23,7 @@ const test: {
24
23
this . commands = { started : [ ] , succeeded : [ ] } ;
25
24
this . client = config . newClient ( { w : 1 } , { maxPoolSize : 1 , monitorCommands : true } ) ;
26
25
27
- // Because we have a MongoClient.connect method, an extra 'ping' event is sent to the
28
- // server when authentication is enabled. We have to detect the scenario when auth is
29
- // enabled for the test and ignore the initial ping. This will be addressed in NODE-2149.
30
- const auth = config . options . auth ;
31
- const isAuthEnabled = ! ! ( auth && auth . username && auth . password ) ;
32
26
this . client . on ( 'commandStarted' , event => {
33
- if ( event . commandName === 'ping' && isAuthEnabled && ! hasInitialPingOccurred ) {
34
- hasInitialPingOccurred = true ;
35
- return ;
36
- }
37
27
if ( ignoredCommands . indexOf ( event . commandName ) === - 1 ) {
38
28
this . commands . started . push ( event ) ;
39
29
}
@@ -70,19 +60,16 @@ describe('Sessions Spec', function () {
70
60
await test . setup ( this . configuration ) ;
71
61
} ) ;
72
62
73
- it ( 'should send endSessions for multiple sessions' , function ( done ) {
63
+ it ( 'should send endSessions for multiple sessions' , async function ( ) {
74
64
const client = test . client ;
75
65
const sessions = [ client . startSession ( ) , client . startSession ( ) ] . map ( s => s . id ) ;
76
66
77
- client . close ( err => {
78
- expect ( err ) . to . not . exist ;
79
- expect ( test . commands . started ) . to . have . length ( 1 ) ;
80
- expect ( test . commands . started [ 0 ] . commandName ) . to . equal ( 'endSessions' ) ;
81
- expect ( test . commands . started [ 0 ] . command . endSessions ) . to . include . deep . members ( sessions ) ;
82
- expect ( client . s . activeSessions . size ) . to . equal ( 0 ) ;
67
+ await client . close ( ) ;
83
68
84
- done ( ) ;
85
- } ) ;
69
+ expect ( test . commands . started ) . to . have . length ( 1 ) ;
70
+ expect ( test . commands . started [ 0 ] . commandName ) . to . equal ( 'endSessions' ) ;
71
+ expect ( test . commands . started [ 0 ] . command . endSessions ) . to . include . deep . members ( sessions ) ;
72
+ expect ( client . s . activeSessions . size ) . to . equal ( 0 ) ;
86
73
} ) ;
87
74
} ) ;
88
75
0 commit comments