Skip to content

Commit 323bb8d

Browse files
authored
test(NODE-3817): refactor RunOn filter in legacy spec runner to use mocha hooks (#3119)
1 parent 6970871 commit 323bb8d

22 files changed

+376
-261
lines changed

.evergreen/run-serverless-tests.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ if [ -z ${MONGODB_URI+omitted} ]; then echo "MONGODB_URI is unset" && exit 1; fi
1111
if [ -z ${SERVERLESS_ATLAS_USER+omitted} ]; then echo "SERVERLESS_ATLAS_USER is unset" && exit 1; fi
1212
if [ -z ${SERVERLESS_ATLAS_PASSWORD+omitted} ]; then echo "SERVERLESS_ATLAS_PASSWORD is unset" && exit 1; fi
1313

14-
npx mocha --file test/tools/runner/index.js \
14+
npx mocha \
15+
--config test/mocha_mongodb.json \
1516
test/integration/crud/crud.spec.test.js \
1617
test/integration/crud/crud.prose.test.js \
1718
test/integration/retryable-reads/retryable_reads.spec.test.js \

.mocharc.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/mocharc.json",
3-
"extension": [
4-
"js",
5-
"ts"
6-
],
73
"require": [
84
"source-map-support/register",
95
"ts-node/register",
10-
"test/tools/runner/chai-addons"
6+
"test/tools/runner/chai-addons.js"
117
],
8+
"extension": ["js", "ts"],
129
"ui": "test/tools/runner/metadata_ui.js",
1310
"recursive": true,
1411
"timeout": 60000,

global.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TestConfiguration } from './test/tools/unified-spec-runner/runner';
1+
import type { TestConfiguration } from './test/tools/runner/config';
22

33
type WithExclusion<T extends string> = `!${T}`
44
/** Defined in test/tools/runner/filters/mongodb_topology_filter.js (topologyTypeToString) */

package.json

+14-14
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
},
9696
"scripts": {
9797
"build:evergreen": "node .evergreen/generate_evergreen_tasks.js",
98-
"build:ts": "rimraf lib && ./node_modules/typescript/bin/tsc",
98+
"build:ts": "rimraf lib && node ./node_modules/typescript/bin/tsc",
9999
"build:dts": "npm run build:ts && api-extractor run && rimraf 'lib/**/*.d.ts*' && downlevel-dts mongodb.d.ts mongodb.ts34.d.ts",
100100
"build:docs": "typedoc",
101101
"check:bench": "node test/benchmarks/driverBench",
@@ -104,19 +104,19 @@
104104
"check:lint": "npm run build:dts && npm run check:dts && npm run check:eslint && npm run check:tsd",
105105
"check:eslint": "eslint -v && eslint --max-warnings=0 --ext '.js,.ts' src test",
106106
"check:tsd": "tsd --version && tsd",
107-
"check:dts": "./node_modules/typescript/bin/tsc --noEmit mongodb.d.ts && tsd",
108-
"check:test": "mocha --file test/tools/runner test/integration",
109-
"check:unit": "mocha test/unit/",
110-
"check:ts": "./node_modules/typescript/bin/tsc -v && ./node_modules/typescript/bin/tsc --noEmit",
111-
"check:atlas": "mocha --config \"test/manual/mocharc.json\" test/manual/atlas_connectivity.test.js",
112-
"check:adl": "mocha --file test/tools/runner test/manual/atlas-data-lake-testing",
113-
"check:aws": "mocha --file test/tools/runner test/integration/auth/mongodb_aws.test.js",
114-
"check:ocsp": "mocha --config \"test/manual/mocharc.json\" test/manual/ocsp_support.test.js",
115-
"check:kerberos": "mocha --config \"test/manual/mocharc.json\" test/manual/kerberos.test.js",
116-
"check:tls": "mocha --config \"test/manual/mocharc.json\" test/manual/tls_support.test.js",
117-
"check:ldap": "mocha --config \"test/manual/mocharc.json\" test/manual/ldap.test.js",
118-
"check:socks5": "mocha --config \"test/manual/mocharc.json\" test/manual/socks5.test.ts",
119-
"check:csfle": "mocha --file test/tools/runner test/integration/client-side-encryption",
107+
"check:dts": "node ./node_modules/typescript/bin/tsc --noEmit mongodb.d.ts && tsd",
108+
"check:test": "mocha --config test/mocha_mongodb.json test/integration",
109+
"check:unit": "mocha test/unit",
110+
"check:ts": "node ./node_modules/typescript/bin/tsc -v && node ./node_modules/typescript/bin/tsc --noEmit",
111+
"check:atlas": "mocha --config test/manual/mocharc.json test/manual/atlas_connectivity.test.js",
112+
"check:adl": "mocha --config test/mocha_mongodb.json test/manual/atlas-data-lake-testing",
113+
"check:aws": "mocha --config test/mocha_mongodb.json test/integration/auth/mongodb_aws.test.js",
114+
"check:ocsp": "mocha --config test/manual/mocharc.json test/manual/ocsp_support.test.js",
115+
"check:kerberos": "mocha --config test/manual/mocharc.json test/manual/kerberos.test.js",
116+
"check:tls": "mocha --config test/manual/mocharc.json test/manual/tls_support.test.js",
117+
"check:ldap": "mocha --config test/manual/mocharc.json test/manual/ldap.test.js",
118+
"check:socks5": "mocha --config test/manual/mocharc.json test/manual/socks5.test.ts",
119+
"check:csfle": "mocha --config test/mocha_mongodb.json test/integration/client-side-encryption",
120120
"check:snappy": "mocha test/unit/assorted/snappy.test.js",
121121
"prepare": "node etc/prepare.js",
122122
"release": "standard-version -i HISTORY.md",

test/integration/retryable-writes/retryable_writes.spec.test.js

+50-33
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,64 @@
22

33
const { expect } = require('chai');
44
const { loadSpecTests } = require('../../spec');
5-
const { parseRunOn } = require('../../tools/spec-runner');
5+
const { legacyRunOnToRunOnRequirement } = require('../../tools/spec-runner');
6+
const { topologySatisfies } = require('../../tools/unified-spec-runner/unified-utils');
67

78
describe('Retryable Writes', function () {
89
let ctx = {};
9-
loadSpecTests('retryable-writes').forEach(suite => {
10-
const environmentRequirementList = parseRunOn(suite.runOn);
11-
environmentRequirementList.forEach(requires => {
12-
const suiteName = `${suite.name} - ${requires.topology.join()}`;
13-
14-
describe(suiteName, {
15-
metadata: { requires },
16-
test: function () {
17-
// Step 3: Test Teardown. Turn off failpoints, and close client
18-
afterEach(function () {
19-
if (!ctx.db || !ctx.client) {
20-
return;
21-
}
10+
const retryableWrites = loadSpecTests('retryable-writes');
11+
12+
for (const suite of retryableWrites) {
13+
describe(suite.name, function () {
14+
beforeEach(async function () {
15+
let utilClient;
16+
if (this.configuration.isLoadBalanced) {
17+
// The util client can always point at the single mongos LB frontend.
18+
utilClient = this.configuration.newClient(this.configuration.singleMongosLoadBalancerUri);
19+
} else {
20+
utilClient = this.configuration.newClient();
21+
}
2222

23-
return Promise.resolve()
24-
.then(() =>
25-
ctx.failPointName ? turnOffFailPoint(ctx.client, ctx.failPointName) : {}
26-
)
27-
.then(() => ctx.client.close())
28-
.then(() => (ctx = {}));
29-
});
23+
await utilClient.connect();
3024

31-
suite.tests.forEach(test => {
32-
it(test.description, function () {
33-
// Step 1: Test Setup. Includes a lot of boilerplate stuff
34-
// like creating a client, dropping and refilling data collections,
35-
// and enabling failpoints
36-
return executeScenarioSetup(suite, test, this.configuration, ctx).then(() =>
37-
// Step 2: Run the test
38-
executeScenarioTest(test, ctx)
39-
);
40-
});
41-
});
25+
const allRequirements = suite.runOn.map(legacyRunOnToRunOnRequirement);
26+
27+
let shouldRun = true;
28+
for (const requirement of allRequirements) {
29+
shouldRun =
30+
shouldRun && (await topologySatisfies(this.currentTest.ctx, requirement, utilClient));
31+
}
32+
33+
await utilClient.close();
34+
35+
if (!shouldRun) this.skip();
36+
});
37+
38+
afterEach(async function () {
39+
// Step 3: Test Teardown. Turn off failpoints, and close client
40+
if (!ctx.db || !ctx.client) {
41+
return;
42+
}
43+
44+
if (ctx.failPointName) {
45+
await turnOffFailPoint(ctx.client, ctx.failPointName);
4246
}
47+
await ctx.client.close();
48+
ctx = {}; // reset context
4349
});
50+
51+
for (const test of suite.tests) {
52+
it(test.description, async function () {
53+
// Step 1: Test Setup. Includes a lot of boilerplate stuff
54+
// like creating a client, dropping and refilling data collections,
55+
// and enabling failpoints
56+
await executeScenarioSetup(suite, test, this.configuration, ctx);
57+
// Step 2: Run the test
58+
await executeScenarioTest(test, ctx);
59+
});
60+
}
4461
});
45-
});
62+
}
4663
});
4764

4865
function executeScenarioSetup(scenario, test, config, ctx) {

test/integration/server-discovery-and-monitoring/server_discovery_and_monitoring.spec.test.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,23 @@ class SDAMRunnerContext extends TestRunnerContext {
3939
}
4040

4141
describe('SDAM', function () {
42-
context('integration spec tests', function () {
42+
describe('integration spec tests', function () {
4343
const testContext = new SDAMRunnerContext();
4444
const testSuites = loadSpecTests('server-discovery-and-monitoring/integration');
45-
after(() => testContext.teardown());
46-
before(function () {
47-
return testContext.setup(this.configuration);
45+
46+
beforeEach(async function () {
47+
if (this.configuration.isLoadBalanced) {
48+
this.currentTest.skipReason = 'Cannot run in a loadBalanced environment';
49+
this.skip();
50+
}
51+
});
52+
53+
beforeEach(async function () {
54+
await testContext.setup(this.configuration);
55+
});
56+
57+
afterEach(async () => {
58+
await testContext.teardown();
4859
});
4960

5061
generateTopologyTests(testSuites, testContext);

test/manual/atlas-data-lake-testing/atlas_data_lake_testing.spec.js

+2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ describe('Atlas Data Lake - spec', function () {
2424
return testContext.setup(this.configuration);
2525
});
2626

27+
for (const suite of testSuites) suite.runOn = []; // patched in for the spec runner
28+
2729
generateTopologyTests(testSuites, testContext);
2830
});

test/mocha_mongodb.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/mocharc.json",
3+
"require": [
4+
"source-map-support/register",
5+
"ts-node/register",
6+
"test/tools/runner/chai-addons.js",
7+
"test/tools/runner/hooks/configuration.js",
8+
"test/tools/runner/hooks/client_leak_checker.js",
9+
"test/tools/runner/hooks/session_leak_checker.js"
10+
],
11+
"extension": ["js", "ts"],
12+
"ui": "test/tools/runner/metadata_ui.js",
13+
"recursive": true,
14+
"timeout": 60000,
15+
"failZero": true,
16+
"reporter": "test/tools/reporter/mongodb_reporter.js",
17+
"sort": true,
18+
"color": true
19+
}

0 commit comments

Comments
 (0)