Skip to content

Commit 8b8a20c

Browse files
committed
refactor: spec test runner should support pre-sessions mongodb
1 parent 11f8792 commit 8b8a20c

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

test/functional/spec-runner/index.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function prepareDatabaseForSuite(suite, context) {
152152
.admin()
153153
.command({ killAllSessions: [] })
154154
.catch(err => {
155-
if (err.code === 11601) {
155+
if (err.code === 11601 || err.message.match(/no such/)) {
156156
return;
157157
}
158158

@@ -259,17 +259,24 @@ function runTestSuiteTest(configuration, spec, context) {
259259

260260
spec.sessionOptions = spec.sessionOptions || {};
261261
const database = client.db(context.dbName);
262-
const session0 = client.startSession(
263-
Object.assign({}, sessionOptions, parseSessionOptions(spec.sessionOptions.session0))
264-
);
265-
const session1 = client.startSession(
266-
Object.assign({}, sessionOptions, parseSessionOptions(spec.sessionOptions.session1))
267-
);
268262

269-
const savedSessionData = {
270-
session0: JSON.parse(EJSON.stringify(session0.id)),
271-
session1: JSON.parse(EJSON.stringify(session1.id))
272-
};
263+
let session0, session1;
264+
let savedSessionData;
265+
try {
266+
session0 = client.startSession(
267+
Object.assign({}, sessionOptions, parseSessionOptions(spec.sessionOptions.session0))
268+
);
269+
session1 = client.startSession(
270+
Object.assign({}, sessionOptions, parseSessionOptions(spec.sessionOptions.session1))
271+
);
272+
273+
savedSessionData = {
274+
session0: JSON.parse(EJSON.stringify(session0.id)),
275+
session1: JSON.parse(EJSON.stringify(session1.id))
276+
};
277+
} catch (err) {
278+
// ignore
279+
}
273280

274281
// enable to see useful APM debug information at the time of actual test run
275282
// displayCommands = true;
@@ -292,8 +299,8 @@ function runTestSuiteTest(configuration, spec, context) {
292299
throw err;
293300
})
294301
.then(() => {
295-
session0.endSession();
296-
session1.endSession();
302+
if (session0) session0.endSession();
303+
if (session1) session1.endSession();
297304

298305
return validateExpectations(context.commandEvents, spec, savedSessionData);
299306
});

0 commit comments

Comments
 (0)