Skip to content

Commit

Permalink
test(NODE-3817): refactor RunOn filter in legacy spec runner to use m…
Browse files Browse the repository at this point in the history
…ocha hooks (#3119)
  • Loading branch information
nbbeeken committed Feb 2, 2022
1 parent 6970871 commit 323bb8d
Show file tree
Hide file tree
Showing 22 changed files with 376 additions and 261 deletions.
3 changes: 2 additions & 1 deletion .evergreen/run-serverless-tests.sh
Expand Up @@ -11,7 +11,8 @@ if [ -z ${MONGODB_URI+omitted} ]; then echo "MONGODB_URI is unset" && exit 1; fi
if [ -z ${SERVERLESS_ATLAS_USER+omitted} ]; then echo "SERVERLESS_ATLAS_USER is unset" && exit 1; fi
if [ -z ${SERVERLESS_ATLAS_PASSWORD+omitted} ]; then echo "SERVERLESS_ATLAS_PASSWORD is unset" && exit 1; fi

npx mocha --file test/tools/runner/index.js \
npx mocha \
--config test/mocha_mongodb.json \
test/integration/crud/crud.spec.test.js \
test/integration/crud/crud.prose.test.js \
test/integration/retryable-reads/retryable_reads.spec.test.js \
Expand Down
7 changes: 2 additions & 5 deletions .mocharc.json
@@ -1,14 +1,11 @@
{
"$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/mocharc.json",
"extension": [
"js",
"ts"
],
"require": [
"source-map-support/register",
"ts-node/register",
"test/tools/runner/chai-addons"
"test/tools/runner/chai-addons.js"
],
"extension": ["js", "ts"],
"ui": "test/tools/runner/metadata_ui.js",
"recursive": true,
"timeout": 60000,
Expand Down
2 changes: 1 addition & 1 deletion global.d.ts
@@ -1,4 +1,4 @@
import type { TestConfiguration } from './test/tools/unified-spec-runner/runner';
import type { TestConfiguration } from './test/tools/runner/config';

type WithExclusion<T extends string> = `!${T}`
/** Defined in test/tools/runner/filters/mongodb_topology_filter.js (topologyTypeToString) */
Expand Down
28 changes: 14 additions & 14 deletions package.json
Expand Up @@ -95,7 +95,7 @@
},
"scripts": {
"build:evergreen": "node .evergreen/generate_evergreen_tasks.js",
"build:ts": "rimraf lib && ./node_modules/typescript/bin/tsc",
"build:ts": "rimraf lib && node ./node_modules/typescript/bin/tsc",
"build:dts": "npm run build:ts && api-extractor run && rimraf 'lib/**/*.d.ts*' && downlevel-dts mongodb.d.ts mongodb.ts34.d.ts",
"build:docs": "typedoc",
"check:bench": "node test/benchmarks/driverBench",
Expand All @@ -104,19 +104,19 @@
"check:lint": "npm run build:dts && npm run check:dts && npm run check:eslint && npm run check:tsd",
"check:eslint": "eslint -v && eslint --max-warnings=0 --ext '.js,.ts' src test",
"check:tsd": "tsd --version && tsd",
"check:dts": "./node_modules/typescript/bin/tsc --noEmit mongodb.d.ts && tsd",
"check:test": "mocha --file test/tools/runner test/integration",
"check:unit": "mocha test/unit/",
"check:ts": "./node_modules/typescript/bin/tsc -v && ./node_modules/typescript/bin/tsc --noEmit",
"check:atlas": "mocha --config \"test/manual/mocharc.json\" test/manual/atlas_connectivity.test.js",
"check:adl": "mocha --file test/tools/runner test/manual/atlas-data-lake-testing",
"check:aws": "mocha --file test/tools/runner test/integration/auth/mongodb_aws.test.js",
"check:ocsp": "mocha --config \"test/manual/mocharc.json\" test/manual/ocsp_support.test.js",
"check:kerberos": "mocha --config \"test/manual/mocharc.json\" test/manual/kerberos.test.js",
"check:tls": "mocha --config \"test/manual/mocharc.json\" test/manual/tls_support.test.js",
"check:ldap": "mocha --config \"test/manual/mocharc.json\" test/manual/ldap.test.js",
"check:socks5": "mocha --config \"test/manual/mocharc.json\" test/manual/socks5.test.ts",
"check:csfle": "mocha --file test/tools/runner test/integration/client-side-encryption",
"check:dts": "node ./node_modules/typescript/bin/tsc --noEmit mongodb.d.ts && tsd",
"check:test": "mocha --config test/mocha_mongodb.json test/integration",
"check:unit": "mocha test/unit",
"check:ts": "node ./node_modules/typescript/bin/tsc -v && node ./node_modules/typescript/bin/tsc --noEmit",
"check:atlas": "mocha --config test/manual/mocharc.json test/manual/atlas_connectivity.test.js",
"check:adl": "mocha --config test/mocha_mongodb.json test/manual/atlas-data-lake-testing",
"check:aws": "mocha --config test/mocha_mongodb.json test/integration/auth/mongodb_aws.test.js",
"check:ocsp": "mocha --config test/manual/mocharc.json test/manual/ocsp_support.test.js",
"check:kerberos": "mocha --config test/manual/mocharc.json test/manual/kerberos.test.js",
"check:tls": "mocha --config test/manual/mocharc.json test/manual/tls_support.test.js",
"check:ldap": "mocha --config test/manual/mocharc.json test/manual/ldap.test.js",
"check:socks5": "mocha --config test/manual/mocharc.json test/manual/socks5.test.ts",
"check:csfle": "mocha --config test/mocha_mongodb.json test/integration/client-side-encryption",
"check:snappy": "mocha test/unit/assorted/snappy.test.js",
"prepare": "node etc/prepare.js",
"release": "standard-version -i HISTORY.md",
Expand Down
83 changes: 50 additions & 33 deletions test/integration/retryable-writes/retryable_writes.spec.test.js
Expand Up @@ -2,47 +2,64 @@

const { expect } = require('chai');
const { loadSpecTests } = require('../../spec');
const { parseRunOn } = require('../../tools/spec-runner');
const { legacyRunOnToRunOnRequirement } = require('../../tools/spec-runner');
const { topologySatisfies } = require('../../tools/unified-spec-runner/unified-utils');

describe('Retryable Writes', function () {
let ctx = {};
loadSpecTests('retryable-writes').forEach(suite => {
const environmentRequirementList = parseRunOn(suite.runOn);
environmentRequirementList.forEach(requires => {
const suiteName = `${suite.name} - ${requires.topology.join()}`;

describe(suiteName, {
metadata: { requires },
test: function () {
// Step 3: Test Teardown. Turn off failpoints, and close client
afterEach(function () {
if (!ctx.db || !ctx.client) {
return;
}
const retryableWrites = loadSpecTests('retryable-writes');

for (const suite of retryableWrites) {
describe(suite.name, function () {
beforeEach(async function () {
let utilClient;
if (this.configuration.isLoadBalanced) {
// The util client can always point at the single mongos LB frontend.
utilClient = this.configuration.newClient(this.configuration.singleMongosLoadBalancerUri);
} else {
utilClient = this.configuration.newClient();
}

return Promise.resolve()
.then(() =>
ctx.failPointName ? turnOffFailPoint(ctx.client, ctx.failPointName) : {}
)
.then(() => ctx.client.close())
.then(() => (ctx = {}));
});
await utilClient.connect();

suite.tests.forEach(test => {
it(test.description, function () {
// Step 1: Test Setup. Includes a lot of boilerplate stuff
// like creating a client, dropping and refilling data collections,
// and enabling failpoints
return executeScenarioSetup(suite, test, this.configuration, ctx).then(() =>
// Step 2: Run the test
executeScenarioTest(test, ctx)
);
});
});
const allRequirements = suite.runOn.map(legacyRunOnToRunOnRequirement);

let shouldRun = true;
for (const requirement of allRequirements) {
shouldRun =
shouldRun && (await topologySatisfies(this.currentTest.ctx, requirement, utilClient));
}

await utilClient.close();

if (!shouldRun) this.skip();
});

afterEach(async function () {
// Step 3: Test Teardown. Turn off failpoints, and close client
if (!ctx.db || !ctx.client) {
return;
}

if (ctx.failPointName) {
await turnOffFailPoint(ctx.client, ctx.failPointName);
}
await ctx.client.close();
ctx = {}; // reset context
});

for (const test of suite.tests) {
it(test.description, async function () {
// Step 1: Test Setup. Includes a lot of boilerplate stuff
// like creating a client, dropping and refilling data collections,
// and enabling failpoints
await executeScenarioSetup(suite, test, this.configuration, ctx);
// Step 2: Run the test
await executeScenarioTest(test, ctx);
});
}
});
});
}
});

function executeScenarioSetup(scenario, test, config, ctx) {
Expand Down
Expand Up @@ -39,12 +39,23 @@ class SDAMRunnerContext extends TestRunnerContext {
}

describe('SDAM', function () {
context('integration spec tests', function () {
describe('integration spec tests', function () {
const testContext = new SDAMRunnerContext();
const testSuites = loadSpecTests('server-discovery-and-monitoring/integration');
after(() => testContext.teardown());
before(function () {
return testContext.setup(this.configuration);

beforeEach(async function () {
if (this.configuration.isLoadBalanced) {
this.currentTest.skipReason = 'Cannot run in a loadBalanced environment';
this.skip();
}
});

beforeEach(async function () {
await testContext.setup(this.configuration);
});

afterEach(async () => {
await testContext.teardown();
});

generateTopologyTests(testSuites, testContext);
Expand Down
Expand Up @@ -24,5 +24,7 @@ describe('Atlas Data Lake - spec', function () {
return testContext.setup(this.configuration);
});

for (const suite of testSuites) suite.runOn = []; // patched in for the spec runner

generateTopologyTests(testSuites, testContext);
});
19 changes: 19 additions & 0 deletions test/mocha_mongodb.json
@@ -0,0 +1,19 @@
{
"$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/mocharc.json",
"require": [
"source-map-support/register",
"ts-node/register",
"test/tools/runner/chai-addons.js",
"test/tools/runner/hooks/configuration.js",
"test/tools/runner/hooks/client_leak_checker.js",
"test/tools/runner/hooks/session_leak_checker.js"
],
"extension": ["js", "ts"],
"ui": "test/tools/runner/metadata_ui.js",
"recursive": true,
"timeout": 60000,
"failZero": true,
"reporter": "test/tools/reporter/mongodb_reporter.js",
"sort": true,
"color": true
}

0 comments on commit 323bb8d

Please sign in to comment.