Skip to content

Commit 06689df

Browse files
mbroadstdaprahamian
authored andcommitted
test: add spec test runner and context for sessions spec tests
1 parent b878287 commit 06689df

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/functional/sessions_tests.js

+49
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
'use strict';
22
const expect = require('chai').expect;
33
const setupDatabase = require('./shared').setupDatabase;
4+
const path = require('path');
5+
const TestRunnerContext = require('./runner').TestRunnerContext;
6+
const gatherTestSuites = require('./runner').gatherTestSuites;
7+
const generateTopologyTests = require('./runner').generateTopologyTests;
48

59
const ignoredCommands = ['ismaster'];
610
const test = { commands: { started: [], succeeded: [] } };
@@ -138,4 +142,49 @@ describe('Sessions', function() {
138142
});
139143
}
140144
});
145+
146+
describe('spec tests', function() {
147+
class SessionSpecTestContext extends TestRunnerContext {
148+
assertSessionNotDirty(options) {
149+
const session = options.session;
150+
expect(session.serverSession.isDirty).to.be.false;
151+
}
152+
153+
assertSessionDirty(options) {
154+
const session = options.session;
155+
expect(session.serverSession.isDirty).to.be.true;
156+
}
157+
158+
assertSameLsidOnLastTwoCommands() {
159+
expect(this.commandEvents).to.have.length.of.at.least(2);
160+
const lastTwoCommands = this.commandEvents.slice(-2).map(c => c.command);
161+
lastTwoCommands.forEach(command => expect(command).to.have.property('lsid'));
162+
expect(lastTwoCommands[0].lsid).to.eql(lastTwoCommands[1].lsid);
163+
}
164+
165+
assertDifferentLsidOnLastTwoCommands() {
166+
expect(this.commandEvents).to.have.length.of.at.least(2);
167+
const lastTwoCommands = this.commandEvents.slice(-2).map(c => c.command);
168+
lastTwoCommands.forEach(command => expect(command).to.have.property('lsid'));
169+
expect(lastTwoCommands[0].lsid).to.not.eql(lastTwoCommands[1].lsid);
170+
}
171+
}
172+
173+
const testContext = new SessionSpecTestContext();
174+
const testSuites = gatherTestSuites(path.join(__dirname, 'spec', 'sessions'));
175+
176+
let shouldRunTests = false;
177+
after(() => testContext.teardown());
178+
before(function() {
179+
shouldRunTests = this.configuration.usingUnifiedTopology();
180+
return testContext.setup(this.configuration);
181+
});
182+
183+
if (!shouldRunTests) {
184+
it.skip('sessions spec tests only run against a unified topology');
185+
return;
186+
}
187+
188+
generateTopologyTests(testSuites, testContext);
189+
});
141190
});

0 commit comments

Comments
 (0)