From d56da5b3f19782d3c699a7fd141de320fa70674a Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Thu, 25 Sep 2025 14:13:26 -0700 Subject: [PATCH 1/2] migrate --- .../sessions/sessions.prose.test.ts | 13 ++++------ test/integration/sessions/sessions.test.ts | 25 ++++++++----------- 2 files changed, 16 insertions(+), 22 deletions(-) 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..c952c9e7da1 100644 --- a/test/integration/sessions/sessions.test.ts +++ b/test/integration/sessions/sessions.test.ts @@ -3,11 +3,11 @@ 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'; @@ -70,19 +70,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); }); }); From 504847acd1cfe2cdf4b7130ef6472f421ee25713 Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Fri, 26 Sep 2025 10:26:12 -0700 Subject: [PATCH 2/2] pr feedback --- test/integration/sessions/sessions.test.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/test/integration/sessions/sessions.test.ts b/test/integration/sessions/sessions.test.ts index c952c9e7da1..f05426ccda6 100644 --- a/test/integration/sessions/sessions.test.ts +++ b/test/integration/sessions/sessions.test.ts @@ -12,7 +12,6 @@ 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); }