|
1 | 1 | 'use strict';
|
2 | 2 | const expect = require('chai').expect;
|
3 | 3 | 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; |
4 | 8 |
|
5 | 9 | const ignoredCommands = ['ismaster'];
|
6 | 10 | const test = { commands: { started: [], succeeded: [] } };
|
@@ -138,4 +142,49 @@ describe('Sessions', function() {
|
138 | 142 | });
|
139 | 143 | }
|
140 | 144 | });
|
| 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 | + }); |
141 | 190 | });
|
0 commit comments