Skip to content

Commit

Permalink
refactor: spec test runner should support pre-sessions mongodb
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Feb 11, 2020
1 parent 11f8792 commit 8b8a20c
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions test/functional/spec-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function prepareDatabaseForSuite(suite, context) {
.admin()
.command({ killAllSessions: [] })
.catch(err => {
if (err.code === 11601) {
if (err.code === 11601 || err.message.match(/no such/)) {
return;
}

Expand Down Expand Up @@ -259,17 +259,24 @@ function runTestSuiteTest(configuration, spec, context) {

spec.sessionOptions = spec.sessionOptions || {};
const database = client.db(context.dbName);
const session0 = client.startSession(
Object.assign({}, sessionOptions, parseSessionOptions(spec.sessionOptions.session0))
);
const session1 = client.startSession(
Object.assign({}, sessionOptions, parseSessionOptions(spec.sessionOptions.session1))
);

const savedSessionData = {
session0: JSON.parse(EJSON.stringify(session0.id)),
session1: JSON.parse(EJSON.stringify(session1.id))
};
let session0, session1;
let savedSessionData;
try {
session0 = client.startSession(
Object.assign({}, sessionOptions, parseSessionOptions(spec.sessionOptions.session0))
);
session1 = client.startSession(
Object.assign({}, sessionOptions, parseSessionOptions(spec.sessionOptions.session1))
);

savedSessionData = {
session0: JSON.parse(EJSON.stringify(session0.id)),
session1: JSON.parse(EJSON.stringify(session1.id))
};
} catch (err) {
// ignore
}

// enable to see useful APM debug information at the time of actual test run
// displayCommands = true;
Expand All @@ -292,8 +299,8 @@ function runTestSuiteTest(configuration, spec, context) {
throw err;
})
.then(() => {
session0.endSession();
session1.endSession();
if (session0) session0.endSession();
if (session1) session1.endSession();

return validateExpectations(context.commandEvents, spec, savedSessionData);
});
Expand Down

0 comments on commit 8b8a20c

Please sign in to comment.