Skip to content

Commit 9242de5

Browse files
test(NODE-3860): improve skipReason reporting for disabled 'auth' tests (#3137)
1 parent 46d5821 commit 9242de5

File tree

9 files changed

+107
-49
lines changed

9 files changed

+107
-49
lines changed

test/integration/causal-consistency/causal_consistency.prose.test.js

+24-16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { LEGACY_HELLO_COMMAND } = require('../../../src/constants');
44

55
const { setupDatabase } = require('../shared');
66
const { expect } = require('chai');
7+
const { skipBrokenAuthTestBeforeEachHook } = require('../../tools/runner/hooks/configuration');
78

89
const ignoredCommands = [LEGACY_HELLO_COMMAND, 'endSessions'];
910
const test = { commands: { started: [], succeeded: [] } };
@@ -14,6 +15,18 @@ describe('Causal Consistency - prose tests', function () {
1415
return setupDatabase(this.configuration);
1516
});
1617

18+
beforeEach(
19+
skipBrokenAuthTestBeforeEachHook({
20+
skippedTests: [
21+
'2. The first read in a causally consistent session must not send afterClusterTime to the server',
22+
'case: successful read with causal consistency',
23+
'case: second operation is findOne',
24+
'case: successful insert',
25+
'6. A read operation in a ClientSession that is not causally consistent should not include the afterClusterTime parameter in the command sent to the server'
26+
]
27+
})
28+
);
29+
1730
beforeEach(function () {
1831
test.commands = { started: [], succeeded: [] };
1932
test.client = this.configuration.newClient({ w: 1 }, { maxPoolSize: 1, monitorCommands: true });
@@ -29,7 +42,7 @@ describe('Causal Consistency - prose tests', function () {
2942
});
3043

3144
afterEach(() => {
32-
return test.client.close();
45+
return test.client ? test.client.close() : Promise.resolve();
3346
});
3447

3548
it(
@@ -42,10 +55,9 @@ describe('Causal Consistency - prose tests', function () {
4255
*/
4356
{
4457
metadata: {
45-
requires: { topology: ['replicaset', 'sharded'], auth: 'disabled' },
58+
requires: { topology: ['replicaset', 'sharded'] },
4659
// Skipping session leak tests b/c these are explicit sessions
47-
sessions: { skipLeakTests: true },
48-
skipReason: 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
60+
sessions: { skipLeakTests: true }
4961
},
5062

5163
test: function () {
@@ -81,10 +93,9 @@ describe('Causal Consistency - prose tests', function () {
8193

8294
it('case: successful read with causal consistency', {
8395
metadata: {
84-
requires: { topology: ['replicaset', 'sharded'], auth: 'disabled' },
96+
requires: { topology: ['replicaset', 'sharded'] },
8597
// Skipping session leak tests b/c these are explicit sessions
86-
sessions: { skipLeakTests: true },
87-
skipReason: 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
98+
sessions: { skipLeakTests: true }
8899
},
89100

90101
test: function () {
@@ -120,10 +131,9 @@ describe('Causal Consistency - prose tests', function () {
120131
() => {
121132
it('case: second operation is findOne', {
122133
metadata: {
123-
requires: { topology: ['replicaset', 'sharded'], auth: 'disabled' },
134+
requires: { topology: ['replicaset', 'sharded'] },
124135
// Skipping session leak tests b/c these are explicit sessions
125-
sessions: { skipLeakTests: true },
126-
skipReason: 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
136+
sessions: { skipLeakTests: true }
127137
},
128138

129139
test: function () {
@@ -166,10 +176,9 @@ describe('Causal Consistency - prose tests', function () {
166176
() => {
167177
it('case: successful insert', {
168178
metadata: {
169-
requires: { topology: ['replicaset', 'sharded'], auth: 'disabled' },
179+
requires: { topology: ['replicaset', 'sharded'] },
170180
// Skipping session leak tests b/c these are explicit sessions
171-
sessions: { skipLeakTests: true },
172-
skipReason: 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
181+
sessions: { skipLeakTests: true }
173182
},
174183

175184
test: function () {
@@ -207,10 +216,9 @@ describe('Causal Consistency - prose tests', function () {
207216
*/
208217
{
209218
metadata: {
210-
requires: { topology: ['replicaset', 'sharded'], auth: 'disabled' },
219+
requires: { topology: ['replicaset', 'sharded'] },
211220
// Skipping session leak tests b/c these are explicit sessions
212-
sessions: { skipLeakTests: true },
213-
skipReason: 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
221+
sessions: { skipLeakTests: true }
214222
},
215223

216224
test: function () {

test/integration/change-streams/change_stream.test.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const { Long, ReadPreference, MongoNetworkError } = require('../../../src');
1111

1212
const crypto = require('crypto');
1313
const { isHello } = require('../../../src/utils');
14+
const { skipBrokenAuthTestBeforeEachHook } = require('../../tools/runner/hooks/configuration');
1415

1516
function withChangeStream(dbName, collectionName, callback) {
1617
if (arguments.length === 1) {
@@ -1253,6 +1254,12 @@ describe('Change Streams', function () {
12531254
return coll.insertOne({ c: 3 });
12541255
}
12551256

1257+
beforeEach(
1258+
skipBrokenAuthTestBeforeEachHook({
1259+
skippedTests: ['when invoked using eventEmitter API']
1260+
})
1261+
);
1262+
12561263
beforeEach(function () {
12571264
client = this.configuration.newClient();
12581265
return client.connect().then(_client => {
@@ -1334,8 +1341,7 @@ describe('Change Streams', function () {
13341341

13351342
it('when invoked using eventEmitter API', {
13361343
metadata: {
1337-
requires: { topology: 'replicaset', mongodb: '>=3.6', auth: 'disabled' },
1338-
skipReason: 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
1344+
requires: { topology: 'replicaset', mongodb: '>=3.6', auth: 'disabled' }
13391345
},
13401346
test: function (done) {
13411347
let closed = false;

test/integration/connection-monitoring-and-pooling/connection.test.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@ const { setupDatabase, withClient, assert: test } = require('../shared');
88
const { ns, HostAddress } = require('../../../src/utils');
99
const { LEGACY_HELLO_COMMAND } = require('../../../src/constants');
1010
const { Topology } = require('../../../src/sdam/topology');
11+
const { skipBrokenAuthTestBeforeEachHook } = require('../../tools/runner/hooks/configuration');
1112

1213
describe('Connection', function () {
14+
beforeEach(
15+
skipBrokenAuthTestBeforeEachHook({
16+
skippedTests: [
17+
'should support calling back multiple times on exhaust commands',
18+
'should correctly connect to server using domain socket'
19+
]
20+
})
21+
);
22+
1323
before(function () {
1424
return setupDatabase(this.configuration);
1525
});
@@ -89,8 +99,7 @@ describe('Connection', function () {
8999

90100
it('should support calling back multiple times on exhaust commands', {
91101
metadata: {
92-
requires: { apiVersion: false, mongodb: '>=4.2.0', topology: ['single'], auth: 'disabled' },
93-
skipReason: 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
102+
requires: { apiVersion: false, mongodb: '>=4.2.0', topology: ['single'] }
94103
},
95104
test: function (done) {
96105
const namespace = ns(`${this.configuration.db}.$cmd`);
@@ -200,8 +209,7 @@ describe('Connection', function () {
200209

201210
it('should correctly connect to server using domain socket', {
202211
metadata: {
203-
requires: { topology: 'single', os: '!win32', auth: 'disabled' },
204-
skipReason: 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
212+
requires: { topology: 'single', os: '!win32' }
205213
},
206214

207215
test: function (done) {

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

+19-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const { expect } = require('chai');
4+
const { skipBrokenAuthTestBeforeEachHook } = require('../../tools/runner/hooks/configuration');
45

56
function ignoreNsNotFound(err) {
67
if (!err.message.match(/ns not found/)) {
@@ -33,6 +34,18 @@ maybeDescribe('Connections survive primary step down - prose', function () {
3334
let db;
3435
let collection;
3536

37+
beforeEach(
38+
skipBrokenAuthTestBeforeEachHook({
39+
skippedTests: [
40+
'getMore iteration',
41+
'Not Primary - Keep Connection Pool',
42+
'Not Primary - Reset Connection Pool',
43+
'Shutdown in progress - Reset Connection Pool',
44+
'Interrupted at shutdown - Reset Connection Pool'
45+
]
46+
})
47+
);
48+
3649
beforeEach(function () {
3750
const clientOptions = {
3851
maxPoolSize: 1,
@@ -67,14 +80,13 @@ maybeDescribe('Connections survive primary step down - prose', function () {
6780
afterEach(function () {
6881
return Promise.all(deferred.map(d => d())).then(() => {
6982
deferred = [];
70-
return Promise.all([client.close(), checkClient.close()]);
83+
return Promise.all([client, checkClient].filter(x => !!x).map(client => client.close()));
7184
});
7285
});
7386

7487
it('getMore iteration', {
7588
metadata: {
76-
requires: { mongodb: '>=4.2.0', topology: 'replicaset', auth: 'disabled' },
77-
skipReason: 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
89+
requires: { mongodb: '>=4.2.0', topology: 'replicaset' }
7890
},
7991

8092
test: function () {
@@ -142,8 +154,7 @@ maybeDescribe('Connections survive primary step down - prose', function () {
142154

143155
it('Not Primary - Keep Connection Pool', {
144156
metadata: {
145-
requires: { mongodb: '>=4.2.0', topology: 'replicaset', auth: 'disabled' },
146-
skipReason: 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
157+
requires: { mongodb: '>=4.2.0', topology: 'replicaset' }
147158
},
148159
test: function () {
149160
return runStepownScenario(10107, expectPoolWasNotCleared);
@@ -152,8 +163,7 @@ maybeDescribe('Connections survive primary step down - prose', function () {
152163

153164
it('Not Primary - Reset Connection Pool', {
154165
metadata: {
155-
requires: { mongodb: '4.0.x', topology: 'replicaset', auth: 'disabled' },
156-
skipReason: 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
166+
requires: { mongodb: '4.0.x', topology: 'replicaset' }
157167
},
158168
test: function () {
159169
return runStepownScenario(10107, expectPoolWasCleared);
@@ -162,8 +172,7 @@ maybeDescribe('Connections survive primary step down - prose', function () {
162172

163173
it('Shutdown in progress - Reset Connection Pool', {
164174
metadata: {
165-
requires: { mongodb: '>=4.0.0', topology: 'replicaset', auth: 'disabled' },
166-
skipReason: 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
175+
requires: { mongodb: '>=4.0.0', topology: 'replicaset' }
167176
},
168177
test: function () {
169178
return runStepownScenario(91, expectPoolWasCleared);
@@ -172,8 +181,7 @@ maybeDescribe('Connections survive primary step down - prose', function () {
172181

173182
it('Interrupted at shutdown - Reset Connection Pool', {
174183
metadata: {
175-
requires: { mongodb: '>=4.0.0', topology: 'replicaset', auth: 'disabled' },
176-
skipReason: 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
184+
requires: { mongodb: '>=4.0.0', topology: 'replicaset' }
177185
},
178186
test: function () {
179187
return runStepownScenario(11600, expectPoolWasCleared);

test/integration/node-specific/operation_example.test.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { Topology } = require('../../../src/sdam/topology');
55
const { Code, ObjectId, ReturnDocument } = require('../../../src');
66

77
const chai = require('chai');
8+
const { skipBrokenAuthTestBeforeEachHook } = require('../../tools/runner/hooks/configuration');
89

910
const expect = chai.expect;
1011
chai.use(require('chai-subset'));
@@ -14,6 +15,15 @@ describe('Operation Examples', function () {
1415
return setupDatabase(this.configuration, ['integration_tests_2']);
1516
});
1617

18+
beforeEach(
19+
skipBrokenAuthTestBeforeEachHook({
20+
skippedTests: [
21+
'Should correctly connect to a replicaset',
22+
'Should connect to mongos proxies using connectiong string'
23+
]
24+
})
25+
);
26+
1727
/**************************************************************************
1828
*
1929
* COLLECTION TESTS
@@ -5488,8 +5498,7 @@ describe('Operation Examples', function () {
54885498
*/
54895499
it('Should correctly connect to a replicaset', {
54905500
metadata: {
5491-
requires: { topology: 'replicaset', auth: 'disabled' },
5492-
skipReason: 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
5501+
requires: { topology: 'replicaset' }
54935502
},
54945503

54955504
test: function (done) {
@@ -5544,8 +5553,7 @@ describe('Operation Examples', function () {
55445553
*/
55455554
it('Should connect to mongos proxies using connectiong string', {
55465555
metadata: {
5547-
requires: { topology: 'sharded', auth: 'disabled' },
5548-
skipReason: 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
5556+
requires: { topology: 'sharded' }
55495557
},
55505558

55515559
test: function (done) {

test/integration/node-specific/operation_promises_example.test.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,23 @@ const { enumToString } = require('../../../src/utils');
66
const { ProfilingLevel } = require('../../../src/operations/set_profiling_level');
77
const { Code, ReturnDocument } = require('../../../src');
88
const { expect } = require('chai');
9+
const { skipBrokenAuthTestBeforeEachHook } = require('../../tools/runner/hooks/configuration');
910

1011
describe('Operation (Promises)', function () {
1112
before(function () {
1213
return setupDatabase(this.configuration, ['integration_tests_2', 'hr', 'reporting']);
1314
});
1415

16+
beforeEach(
17+
skipBrokenAuthTestBeforeEachHook({
18+
skippedTests: [
19+
'Should correctly connect to a replicaset',
20+
'Should connect to mongos proxies using connectiong string With Promises',
21+
'Should correctly connect to a replicaset With Promises'
22+
]
23+
})
24+
);
25+
1526
/**************************************************************************
1627
*
1728
* COLLECTION TESTS
@@ -4016,8 +4027,7 @@ describe('Operation (Promises)', function () {
40164027
*/
40174028
it('Should correctly connect to a replicaset With Promises', {
40184029
metadata: {
4019-
requires: { topology: 'replicaset', auth: 'disabled' },
4020-
skipReason: 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
4030+
requires: { topology: 'replicaset' }
40214031
},
40224032

40234033
test: function () {
@@ -4064,8 +4074,7 @@ describe('Operation (Promises)', function () {
40644074
*/
40654075
it('Should connect to mongos proxies using connectiong string With Promises', {
40664076
metadata: {
4067-
requires: { topology: 'sharded', auth: 'disabled' },
4068-
skipReason: 'TODO: NODE-3891 - fix tests broken when AUTH enabled'
4077+
requires: { topology: 'sharded' }
40694078
},
40704079

40714080
test: function () {

test/tools/reporter/mongodb_reporter.js

-5
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,6 @@ class MongoDBMochaReporter extends mocha.reporters.Spec {
233233
*/
234234
pending(test) {
235235
if (REPORT_TO_STDIO) console.log(chalk.cyan(`↬ ${test.fullTitle()}`));
236-
if (test.metadata && test.metadata.skipReason && typeof test.metadata.skipReason === 'string') {
237-
console.log(
238-
chalk.cyan(`${' '.repeat(test.titlePath().length + 1)}${test.metadata.skipReason}`)
239-
);
240-
}
241236
if (typeof test.skipReason === 'string') {
242237
console.log(chalk.cyan(`${' '.repeat(test.titlePath().length + 1)}${test.skipReason}`));
243238
}

test/tools/runner/hooks/configuration.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ const testSkipBeforeEachHook = async function () {
8888
}
8989
};
9090

91+
// TODO: NODE-3891 - fix tests that are broken with auth enabled and remove this hook
92+
const skipBrokenAuthTestBeforeEachHook = function ({ skippedTests } = { skippedTests: [] }) {
93+
return function () {
94+
if (process.env.AUTH === 'auth' && skippedTests.includes(this.currentTest.title)) {
95+
this.currentTest.skipReason = 'TODO: NODE-3891 - fix tests broken when AUTH enabled';
96+
this.skip();
97+
}
98+
};
99+
};
100+
91101
const testConfigBeforeHook = async function () {
92102
const client = new MongoClient(loadBalanced ? SINGLE_MONGOS_LB_URI : MONGODB_URI, {
93103
...getEnvironmentalOptions()
@@ -152,5 +162,6 @@ module.exports = {
152162
beforeAll: [beforeAllPluginImports, testConfigBeforeHook],
153163
beforeEach: [testSkipBeforeEachHook],
154164
afterAll: [cleanUpMocksAfterHook]
155-
}
165+
},
166+
skipBrokenAuthTestBeforeEachHook
156167
};

0 commit comments

Comments
 (0)