Skip to content

Commit 7e04ef4

Browse files
Merge branch 'mongodb:main' into NODE-7180
2 parents 937fa0f + 28b8718 commit 7e04ef4

File tree

4 files changed

+37
-62
lines changed

4 files changed

+37
-62
lines changed

test/integration/sessions/sessions.prose.test.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1+
import { ObjectId } from 'bson';
12
import { expect } from 'chai';
23
import { type ChildProcess, spawn } from 'child_process';
34
import { once } from 'events';
45
import * as os from 'os';
56
import * as path from 'path';
67

7-
import {
8-
type Collection,
9-
type CommandStartedEvent,
10-
MongoClient,
11-
MongoDriverError,
12-
MongoInvalidArgumentError,
13-
ObjectId
14-
} from '../../mongodb';
8+
import { type CommandStartedEvent } from '../../../src/cmap/command_monitoring_events';
9+
import { type Collection } from '../../../src/collection';
10+
import { MongoDriverError, MongoInvalidArgumentError } from '../../../src/error';
11+
import { MongoClient } from '../../../src/mongo_client';
1512
import { sleep } from '../../tools/utils';
1613

1714
describe('Sessions Prose Tests', () => {

test/integration/sessions/sessions.test.ts

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ import { MongoClient as LegacyMongoClient } from 'mongodb-legacy';
33

44
import {
55
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';
1111
import type { TestConfiguration } from '../../tools/runner/config';
1212
import { setupDatabase } from '../shared';
1313

1414
const ignoredCommands = [LEGACY_HELLO_COMMAND];
15-
let hasInitialPingOccurred = false;
1615
const test: {
1716
client: MongoClient;
1817
commands: { started: CommandStartedEvent[]; succeeded: CommandSucceededEvent[] };
@@ -24,16 +23,7 @@ const test: {
2423
this.commands = { started: [], succeeded: [] };
2524
this.client = config.newClient({ w: 1 }, { maxPoolSize: 1, monitorCommands: true });
2625

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);
3226
this.client.on('commandStarted', event => {
33-
if (event.commandName === 'ping' && isAuthEnabled && !hasInitialPingOccurred) {
34-
hasInitialPingOccurred = true;
35-
return;
36-
}
3727
if (ignoredCommands.indexOf(event.commandName) === -1) {
3828
this.commands.started.push(event);
3929
}
@@ -70,19 +60,16 @@ describe('Sessions Spec', function () {
7060
await test.setup(this.configuration);
7161
});
7262

73-
it('should send endSessions for multiple sessions', function (done) {
63+
it('should send endSessions for multiple sessions', async function () {
7464
const client = test.client;
7565
const sessions = [client.startSession(), client.startSession()].map(s => s.id);
7666

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();
8368

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);
8673
});
8774
});
8875

test/integration/transactions/transactions.prose.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { type ObjectId } from 'bson';
12
import { expect } from 'chai';
23

3-
import { type MongoClient, type ObjectId } from '../../mongodb';
4+
import { type MongoClient } from '../../../src/mongo_client';
45

56
const metadata: MongoDBMetadataUI = {
67
requires: {

test/integration/transactions/transactions.test.ts

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import { expect } from 'chai';
22

3-
import {
4-
ClientSession,
5-
type Collection,
6-
type CommandStartedEvent,
7-
type MongoClient,
8-
MongoInvalidArgumentError,
9-
MongoNetworkError,
10-
type ServerSessionPool
11-
} from '../../mongodb';
3+
import { type CommandStartedEvent } from '../../../src/cmap/command_monitoring_events';
4+
import { type Collection } from '../../../src/collection';
5+
import { MongoInvalidArgumentError, MongoNetworkError } from '../../../src/error';
6+
import { type MongoClient } from '../../../src/mongo_client';
7+
import { ClientSession, type ServerSessionPool } from '../../../src/sessions';
128
import { type FailCommandFailPoint } from '../../tools/utils';
139

1410
describe('Transactions', function () {
@@ -55,18 +51,14 @@ describe('Transactions', function () {
5551
metadata: {
5652
requires: { topology: ['replicaset', 'sharded'] }
5753
},
58-
test: function (done) {
54+
test: async function () {
5955
function fnThatReturnsBadPromise() {
6056
return Promise.reject();
6157
}
6258

63-
session
64-
.withTransaction(fnThatReturnsBadPromise)
65-
.then(() => done(Error('Expected error')))
66-
.catch(err => {
67-
expect(err).to.equal(undefined);
68-
session.endSession(done);
69-
});
59+
const err = await session.withTransaction(fnThatReturnsBadPromise).catch(err => err);
60+
expect(err).to.equal(undefined);
61+
await session.endSession();
7062
}
7163
});
7264

@@ -179,23 +171,21 @@ describe('Transactions', function () {
179171
describe('startTransaction', function () {
180172
it('should not error if transactions are supported', {
181173
metadata: { requires: { topology: ['sharded'] } },
182-
test: function (done) {
174+
test: async function () {
183175
const configuration = this.configuration;
184176
const client = configuration.newClient(configuration.url());
185177

186-
client.connect(err => {
187-
expect(err).to.not.exist;
178+
await client.connect();
188179

189-
const session = client.startSession();
190-
const db = client.db(configuration.db);
191-
const coll = db.collection('transaction_error_test');
192-
coll.insertOne({ a: 1 }, err => {
193-
expect(err).to.not.exist;
194-
expect(() => session.startTransaction()).to.not.throw();
180+
const session = client.startSession();
181+
const db = client.db(configuration.db);
182+
const coll = db.collection('transaction_error_test');
183+
await coll.insertOne({ a: 1 });
184+
session.startTransaction();
195185

196-
session.abortTransaction(() => session.endSession(() => client.close(done)));
197-
});
198-
});
186+
await session.abortTransaction();
187+
await session.endSession();
188+
await client.close();
199189
}
200190
});
201191
});

0 commit comments

Comments
 (0)