Skip to content

Commit c81c506

Browse files
authored
test(NODE-3719): fix max staleness test to assert against correct set and other clean up (#3116)
1 parent dd81438 commit c81c506

File tree

4 files changed

+24
-33
lines changed

4 files changed

+24
-33
lines changed

test/integration/connections-survive-step-down/connections_stepdown.test.js renamed to test/integration/connections-survive-step-down/connections_survive_step_down.prose.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ function expectPoolWasNotCleared(initialCount) {
2525
}
2626

2727
// TODO: NODE-3819: Unskip flaky MacOS tests.
28+
// TODO: NODE-3903: check events as specified in the corresponding prose test description
2829
const maybeDescribe = process.platform === 'darwin' ? describe.skip : describe;
29-
maybeDescribe('Connections survive primary step down', function () {
30+
maybeDescribe('Connections survive primary step down - prose', function () {
3031
let client;
3132
let checkClient;
3233
let db;

test/unit/assorted/max_staleness.spec.test.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,8 @@ describe('Max Staleness (spec)', function () {
4747
Object.keys(specTests).forEach(specTestName => {
4848
describe(specTestName, () => {
4949
specTests[specTestName].forEach(testData => {
50-
it(testData.description, {
51-
metadata: { requires: { topology: 'single' } },
52-
test: function (done) {
53-
executeServerSelectionTest(testData, { checkLatencyWindow: false }, done);
54-
}
50+
it(testData.description, function (done) {
51+
executeServerSelectionTest(testData, done);
5552
});
5653
});
5754
});

test/unit/assorted/server_selection.spec.test.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,7 @@ describe('Server Selection (spec)', function () {
6363
const maybeIt = test.name.match(/Possible/) ? it.skip : it;
6464

6565
maybeIt(test.name, function (done) {
66-
executeServerSelectionTest(test, { checkLatencyWindow: false }, done);
67-
});
68-
});
69-
});
70-
71-
describe(subType + ' (within latency window)', function () {
72-
specTests[topologyType][subType].forEach(test => {
73-
// NOTE: node does not support PossiblePrimary
74-
const maybeIt = test.name.match(/Possible/) ? it.skip : it;
75-
76-
maybeIt(test.name, function (done) {
77-
executeServerSelectionTest(test, { checkLatencyWindow: true }, done);
66+
executeServerSelectionTest(test, done);
7867
});
7968
});
8069
});

test/unit/assorted/server_selection_spec_helper.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ const { MongoServerSelectionError } = require('../../../src/error');
77
const ServerSelectors = require('../../../src/sdam/server_selection');
88

99
const sinon = require('sinon');
10-
const chai = require('chai');
11-
12-
const expect = chai.expect;
13-
chai.use(require('chai-subset'));
10+
const { expect } = require('chai');
1411

1512
function serverDescriptionFromDefinition(definition, hosts) {
1613
hosts = hosts || [];
@@ -82,7 +79,7 @@ function readPreferenceFromDefinition(definition) {
8279
return new ReadPreference(mode, tags, options);
8380
}
8481

85-
function executeServerSelectionTest(testDefinition, options, testDone) {
82+
function executeServerSelectionTest(testDefinition, testDone) {
8683
const topologyDescription = testDefinition.topology_description;
8784
const seedData = topologyDescription.servers.reduce(
8885
(result, seed) => {
@@ -140,15 +137,9 @@ function executeServerSelectionTest(testDefinition, options, testDone) {
140137
// expectations
141138
let expectedServers;
142139
if (!testDefinition.error) {
143-
if (options.checkLatencyWindow) {
144-
expectedServers = testDefinition.in_latency_window.map(s =>
145-
serverDescriptionFromDefinition(s)
146-
);
147-
} else {
148-
expectedServers = testDefinition.suitable_servers.map(s =>
149-
serverDescriptionFromDefinition(s)
150-
);
151-
}
140+
expectedServers = testDefinition.in_latency_window.map(s =>
141+
serverDescriptionFromDefinition(s)
142+
);
152143
}
153144

154145
// default to serverSelectionTimeoutMS of `100` for unit tests
@@ -183,7 +174,20 @@ function executeServerSelectionTest(testDefinition, options, testDone) {
183174
return done(new Error('No suitable servers found!'));
184175
}
185176

186-
expect(selectedServerDescription).to.include.containSubset(expectedServerArray[0]);
177+
if (expectedServerArray.length > 1) {
178+
return done(new Error('This test does not support multiple expected servers'));
179+
}
180+
181+
for (const [prop, value] of Object.entries(expectedServerArray[0])) {
182+
if (prop === 'hosts') {
183+
// we dynamically modify this prop during sever selection
184+
continue;
185+
}
186+
expect(selectedServerDescription[prop]).to.deep.equal(
187+
value,
188+
`Mismatched selected server "${prop}"`
189+
);
190+
}
187191
done();
188192
} catch (e) {
189193
done(e);

0 commit comments

Comments
 (0)