diff --git a/test/integration/sessions/sessions.prose.test.ts b/test/integration/sessions/sessions.prose.test.ts index 7e43de294ba..3ee78cdf699 100644 --- a/test/integration/sessions/sessions.prose.test.ts +++ b/test/integration/sessions/sessions.prose.test.ts @@ -1,17 +1,14 @@ +import { ObjectId } from 'bson'; import { expect } from 'chai'; import { type ChildProcess, spawn } from 'child_process'; import { once } from 'events'; import * as os from 'os'; import * as path from 'path'; -import { - type Collection, - type CommandStartedEvent, - MongoClient, - MongoDriverError, - MongoInvalidArgumentError, - ObjectId -} from '../../mongodb'; +import { type CommandStartedEvent } from '../../../src/cmap/command_monitoring_events'; +import { type Collection } from '../../../src/collection'; +import { MongoDriverError, MongoInvalidArgumentError } from '../../../src/error'; +import { MongoClient } from '../../../src/mongo_client'; import { sleep } from '../../tools/utils'; describe('Sessions Prose Tests', () => { diff --git a/test/integration/sessions/sessions.test.ts b/test/integration/sessions/sessions.test.ts index ccedd595868..f05426ccda6 100644 --- a/test/integration/sessions/sessions.test.ts +++ b/test/integration/sessions/sessions.test.ts @@ -3,16 +3,15 @@ import { MongoClient as LegacyMongoClient } from 'mongodb-legacy'; import { type CommandStartedEvent, - type CommandSucceededEvent, - LEGACY_HELLO_COMMAND, - type MongoClient, - MongoServerError -} from '../../mongodb'; + type CommandSucceededEvent +} from '../../../src/cmap/command_monitoring_events'; +import { LEGACY_HELLO_COMMAND } from '../../../src/constants'; +import { MongoServerError } from '../../../src/error'; +import { type MongoClient } from '../../../src/mongo_client'; import type { TestConfiguration } from '../../tools/runner/config'; import { setupDatabase } from '../shared'; const ignoredCommands = [LEGACY_HELLO_COMMAND]; -let hasInitialPingOccurred = false; const test: { client: MongoClient; commands: { started: CommandStartedEvent[]; succeeded: CommandSucceededEvent[] }; @@ -24,16 +23,7 @@ const test: { this.commands = { started: [], succeeded: [] }; this.client = config.newClient({ w: 1 }, { maxPoolSize: 1, monitorCommands: true }); - // Because we have a MongoClient.connect method, an extra 'ping' event is sent to the - // server when authentication is enabled. We have to detect the scenario when auth is - // enabled for the test and ignore the initial ping. This will be addressed in NODE-2149. - const auth = config.options.auth; - const isAuthEnabled = !!(auth && auth.username && auth.password); this.client.on('commandStarted', event => { - if (event.commandName === 'ping' && isAuthEnabled && !hasInitialPingOccurred) { - hasInitialPingOccurred = true; - return; - } if (ignoredCommands.indexOf(event.commandName) === -1) { this.commands.started.push(event); } @@ -70,19 +60,16 @@ describe('Sessions Spec', function () { await test.setup(this.configuration); }); - it('should send endSessions for multiple sessions', function (done) { + it('should send endSessions for multiple sessions', async function () { const client = test.client; const sessions = [client.startSession(), client.startSession()].map(s => s.id); - client.close(err => { - expect(err).to.not.exist; - expect(test.commands.started).to.have.length(1); - expect(test.commands.started[0].commandName).to.equal('endSessions'); - expect(test.commands.started[0].command.endSessions).to.include.deep.members(sessions); - expect(client.s.activeSessions.size).to.equal(0); + await client.close(); - done(); - }); + expect(test.commands.started).to.have.length(1); + expect(test.commands.started[0].commandName).to.equal('endSessions'); + expect(test.commands.started[0].command.endSessions).to.include.deep.members(sessions); + expect(client.s.activeSessions.size).to.equal(0); }); });