Skip to content

Commit

Permalink
test: legacy spec runner improvements (#2917)
Browse files Browse the repository at this point in the history
  • Loading branch information
emadum committed Jul 23, 2021
1 parent 4a10389 commit c67daea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
52 changes: 27 additions & 25 deletions test/functional/spec-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,35 +129,15 @@ function generateTopologyTests(testSuites, testContext, filter) {
environmentRequirementList.forEach(requires => {
const suiteName = `${testSuite.name} - ${requires.topology.join()}`;
describe(suiteName, {
// FIXME: calling this.skip() inside tests triggers the leak checker, disable until fixed
metadata: { requires, sessions: { skipLeakTests: true } },
metadata: { requires },
test: function () {
beforeEach(() => prepareDatabaseForSuite(testSuite, testContext));
afterEach(() => testContext.cleanupAfterSuite());
testSuite.tests.forEach(spec => {
it(spec.description, function () {
if (requires.authEnabled && process.env.AUTH !== 'auth') {
// TODO: We do not have a way to determine if auth is enabled in our mocha metadata
// We need to do a admin.command({getCmdLineOpts: 1}) if it errors (code=13) auth is on
this.skip();
}

if (
spec.operations.some(
op => op.name === 'waitForEvent' && op.arguments.event === 'PoolReadyEvent'
)
) {
// TODO(NODE-2994): Connection storms work will add new events to connection pool
this.skip();
}

if (
spec.skipReason ||
(filter && typeof filter === 'function' && !filter(spec, this.configuration))
) {
return this.skip();
}

const maybeIt = shouldRunSpecTest(this.configuration, requires, spec, filter)
? it
: it.skip;
maybeIt(spec.description, function () {
let testPromise = Promise.resolve();
if (spec.failPoint) {
testPromise = testPromise.then(() => testContext.enableFailPoint(spec.failPoint));
Expand All @@ -180,6 +160,28 @@ function generateTopologyTests(testSuites, testContext, filter) {
});
}

function shouldRunSpecTest(configuration, requires, spec, filter) {
if (requires.authEnabled && process.env.AUTH !== 'auth') {
// TODO(NODE-3488): We do not have a way to determine if auth is enabled in our mocha metadata
// We need to do a admin.command({getCmdLineOpts: 1}) if it errors (code=13) auth is on
return false;
}

if (
spec.operations.some(
op => op.name === 'waitForEvent' && op.arguments.event === 'PoolReadyEvent'
)
) {
// TODO(NODE-2994): Connection storms work will add new events to connection pool
return false;
}

if (spec.skipReason || (filter && typeof filter === 'function' && !filter(spec, configuration))) {
return false;
}
return true;
}

// Test runner helpers
function prepareDatabaseForSuite(suite, context) {
context.dbName = suite.database_name || 'spec_db';
Expand Down
2 changes: 1 addition & 1 deletion test/functional/spec-runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function resolveConnectionString(configuration, spec, context) {
isShardedEnvironment && !useMultipleMongoses
? `mongodb://${configuration.host}:${configuration.port}/${
configuration.db
}?directConnection=false${authSource ? '&authSource=${authSource}' : ''}`
}?directConnection=false${authSource ? `&authSource=${authSource}` : ''}`
: configuration.url({ username, password, authSource });
return connectionString;
}
Expand Down

0 comments on commit c67daea

Please sign in to comment.