Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions test/integration/sessions/sessions.prose.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
35 changes: 11 additions & 24 deletions test/integration/sessions/sessions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] };
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
});
});

Expand Down