Skip to content

Commit

Permalink
test(transactions): ensure lsids are saved before cleanup
Browse files Browse the repository at this point in the history
This modifies the test runner to run to spec by saving off the
session ids when they are created so that they can be used to check
expectations after cleanup. With the changes introduced in the core
component to this PR the id's are actually explicitly reset when
`endSession` is called, so the test was succeeding by side effect
previously.
  • Loading branch information
mbroadst committed Mar 10, 2019
1 parent 425cc6e commit b4bc157
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions test/functional/transactions_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,16 @@ function runTestSuiteTest(configuration, spec, context) {
// enable to see useful APM debug information at the time of actual test run
// displayCommands = true;

const operationContext = { database, session0, session1, testRunner: context };
const operationContext = {
database,
session0,
session1,
testRunner: context,
savedSessionData: {
session0: JSON.parse(EJSON.stringify(session0.id)),
session1: JSON.parse(EJSON.stringify(session1.id))
}
};

let testPromise = Promise.resolve();
return testPromise
Expand Down Expand Up @@ -440,13 +449,10 @@ function validateOutcome(testData, testContext) {
}

function validateExpectations(commandEvents, spec, testContext, operationContext) {
const session0 = operationContext.session0;
const session1 = operationContext.session1;

if (spec.expectations && Array.isArray(spec.expectations) && spec.expectations.length > 0) {
const actualEvents = normalizeCommandShapes(commandEvents);
const rawExpectedEvents = spec.expectations.map(x =>
linkSessionData(x.command_started_event, { session0, session1 })
linkSessionData(x.command_started_event, operationContext.savedSessionData)
);

const expectedEventPlaceholders = rawExpectedEvents.map(event =>
Expand Down Expand Up @@ -496,9 +502,8 @@ function validateExpectations(commandEvents, spec, testContext, operationContext
}

function linkSessionData(command, context) {
const session = context[command.command.lsid];
const result = Object.assign({}, command);
result.command.lsid = JSON.parse(EJSON.stringify(session.id));
result.command.lsid = context[command.command.lsid];
return result;
}

Expand Down

0 comments on commit b4bc157

Please sign in to comment.