Skip to content

chore(e2e-tests): refactor TestShell to ensure killAll gets called #2170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
"url": "git://github.com/mongodb-js/mongosh.git"
},
"scripts": {
"test": "mocha -r \"../../scripts/import-expansions.js\" --timeout 15000 --colors -r ts-node/register \"./test/e2e*.spec.ts\"",
"test": "mocha -r ts-node/register -r \"../../scripts/import-expansions.js\" -r \"./test/test-shell-context.ts\" --timeout 15000 --colors \"./test/*.spec.ts\"",
"test-ci": "node ../../scripts/run-if-package-requested.js npm test",
"test-coverage": "nyc --no-clean --cwd ../.. --reporter=none npm run test",
"test-ci-coverage": "nyc --no-clean --cwd ../.. --reporter=none npm run test-ci",
11 changes: 4 additions & 7 deletions packages/e2e-tests/test/e2e-analytics.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect } from 'chai';
import { startTestCluster } from '../../../testing/integration-testing-hooks';
import { eventually } from '../../../testing/eventually';
import { TestShell } from './test-shell';

describe('e2e Analytics Node', function () {
const replSetName = 'replicaSet';
@@ -13,8 +12,6 @@ describe('e2e Analytics Node', function () {
{ args: ['--replSet', replSetName] }
);

afterEach(TestShell.cleanup);

before(async function () {
if (process.env.MONGOSH_TEST_FORCE_API_STRICT) {
return this.skip();
@@ -36,7 +33,7 @@ describe('e2e Analytics Node', function () {
],
};

const shell = TestShell.start({
const shell = this.startTestShell({
args: [await rs0.connectionString()],
});
await shell.waitForPrompt();
@@ -55,7 +52,7 @@ describe('e2e Analytics Node', function () {

context('without readPreference', function () {
it('a direct connection ends up at primary', async function () {
const shell = TestShell.start({
const shell = this.startTestShell({
args: [await rs0.connectionString()],
});
await shell.waitForPrompt();
@@ -68,13 +65,13 @@ describe('e2e Analytics Node', function () {

context('specifying readPreference and tags', function () {
it('ends up at the ANALYTICS node', async function () {
const shell = TestShell.start({
const shell = this.startTestShell({
args: [
`${await rs0.connectionString()}?replicaSet=${replSetName}&readPreference=secondary&readPreferenceTags=nodeType:ANALYTICS`,
],
});

const directConnectionToAnalyticsShell = TestShell.start({
const directConnectionToAnalyticsShell = this.startTestShell({
args: [`${await rs3.connectionString()}?directConnection=true`],
});
await Promise.all([
26 changes: 12 additions & 14 deletions packages/e2e-tests/test/e2e-auth.spec.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { expect } from 'chai';
import type { Db, Document, MongoClientOptions } from 'mongodb';
import { MongoClient } from 'mongodb';
import { eventually } from '../../../testing/eventually';
import { TestShell } from './test-shell';
import type { TestShell } from './test-shell';
import {
skipIfApiStrict,
startSharedTestServer,
@@ -110,7 +110,7 @@ describe('Auth e2e', function () {
beforeEach(async function () {
const connectionString = await testServer.connectionString();
dbName = `test-${Date.now()}`;
shell = TestShell.start({ args: [connectionString] });
shell = this.startTestShell({ args: [connectionString] });

client = await MongoClient.connect(connectionString, {});

@@ -137,7 +137,6 @@ describe('Auth e2e', function () {

await client.close();
});
afterEach(TestShell.cleanup);

describe('user management', function () {
describe('createUser', function () {
@@ -879,7 +878,7 @@ describe('Auth e2e', function () {
pathname: `/${dbName}`,
}
);
shell = TestShell.start({ args: [authConnectionString] });
shell = this.startTestShell({ args: [authConnectionString] });
await shell.waitForPrompt();
shell.assertNoErrors();
await shell.executeLine(`use ${dbName}`);
@@ -903,7 +902,7 @@ describe('Auth e2e', function () {
pathname: `/${dbName}`,
}
);
shell = TestShell.start({ args: [authConnectionString] });
shell = this.startTestShell({ args: [authConnectionString] });
await shell.waitForPrompt();
shell.assertNoErrors();
await shell.executeLine(`use ${dbName}`);
@@ -930,7 +929,7 @@ describe('Auth e2e', function () {
});
it('can auth when there is -u and -p', async function () {
const connectionString = await testServer.connectionString();
shell = TestShell.start({
shell = this.startTestShell({
args: [
connectionString,
'-u',
@@ -965,7 +964,7 @@ describe('Auth e2e', function () {
return this.skip(); // No SCRAM-SHA-1 in FIPS mode
}
const connectionString = await testServer.connectionString();
shell = TestShell.start({
shell = this.startTestShell({
args: [
connectionString,
'-u',
@@ -989,7 +988,7 @@ describe('Auth e2e', function () {
// This test is not particularly meaningful if we're using the system OpenSSL installation
// and it is not properly configured for FIPS to begin with. This is the case on e.g.
// Ubuntu 22.04 in evergreen CI.
const preTestShell = TestShell.start({
const preTestShell = this.startTestShell({
args: [
'--quiet',
'--nodb',
@@ -1009,7 +1008,7 @@ describe('Auth e2e', function () {
}

const connectionString = await testServer.connectionString();
shell = TestShell.start({
shell = this.startTestShell({
args: [
connectionString,
'--tlsFIPSMode',
@@ -1034,7 +1033,7 @@ describe('Auth e2e', function () {
});
it('can auth with SCRAM-SHA-256', async function () {
const connectionString = await testServer.connectionString();
shell = TestShell.start({
shell = this.startTestShell({
args: [
connectionString,
'-u',
@@ -1055,7 +1054,7 @@ describe('Auth e2e', function () {
});
it('cannot auth when authenticationMechanism mismatches (sha256 -> sha1)', async function () {
const connectionString = await testServer.connectionString();
shell = TestShell.start({
shell = this.startTestShell({
args: [
connectionString,
'-u',
@@ -1076,7 +1075,7 @@ describe('Auth e2e', function () {
});
it('cannot auth when authenticationMechanism mismatches (sha1 -> sha256)', async function () {
const connectionString = await testServer.connectionString();
shell = TestShell.start({
shell = this.startTestShell({
args: [
connectionString,
'-u',
@@ -1097,7 +1096,7 @@ describe('Auth e2e', function () {
});
it('does not fail with kerberos not found for GSSAPI', async function () {
const connectionString = await testServer.connectionString();
shell = TestShell.start({
shell = this.startTestShell({
args: [
connectionString,
'-u',
@@ -1144,6 +1143,5 @@ describe('Auth e2e', function () {

await client.close();
});
afterEach(TestShell.cleanup);
});
});
19 changes: 8 additions & 11 deletions packages/e2e-tests/test/e2e-aws.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect } from 'chai';
import { spawnSync } from 'child_process';
import { TestShell } from './test-shell';

function assertEnvVariable(variableName: string): string {
if (process.env.MONGOSH_TEST_FORCE_API_STRICT) {
@@ -117,12 +116,10 @@ describe('e2e AWS AUTH', function () {
).replace('arn:aws:iam::', 'arn:aws:sts::')}/*`;
});

afterEach(TestShell.cleanup);

context('without environment variables being present', function () {
context('specifying explicit parameters', function () {
it('connects with access key and secret', async function () {
const shell = TestShell.start({
const shell = this.startTestShell({
args: [
getConnectionString(),
'--username',
@@ -142,7 +139,7 @@ describe('e2e AWS AUTH', function () {

it('connects with access key, secret, and session token for IAM role', async function () {
const tokenDetails = generateIamSessionToken();
const shell = TestShell.start({
const shell = this.startTestShell({
args: [
getConnectionString(),
'--username',
@@ -165,7 +162,7 @@ describe('e2e AWS AUTH', function () {

context('specifying connection string parameters', function () {
it('connects with access key and secret', async function () {
const shell = TestShell.start({
const shell = this.startTestShell({
args: [getConnectionString(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)],
});
const result = await shell.waitForPromptOrExit();
@@ -179,7 +176,7 @@ describe('e2e AWS AUTH', function () {

it('connects with access key, secret, and session token for IAM role', async function () {
const tokenDetails = generateIamSessionToken();
const shell = TestShell.start({
const shell = this.startTestShell({
args: [
`${getConnectionString(
tokenDetails.key,
@@ -203,7 +200,7 @@ describe('e2e AWS AUTH', function () {
context('with AWS environment variables', function () {
context('without any other parameters', function () {
it('connects for the IAM user', async function () {
const shell = TestShell.start({
const shell = this.startTestShell({
args: [getConnectionString()],
env: {
...process.env,
@@ -222,7 +219,7 @@ describe('e2e AWS AUTH', function () {

it('connects for the IAM role session', async function () {
const tokenDetails = generateIamSessionToken();
const shell = TestShell.start({
const shell = this.startTestShell({
args: [getConnectionString()],
env: {
...process.env,
@@ -243,7 +240,7 @@ describe('e2e AWS AUTH', function () {

context('with invalid environment but valid parameters', function () {
it('connects for the IAM user', async function () {
const shell = TestShell.start({
const shell = this.startTestShell({
args: [
getConnectionString(),
'--username',
@@ -268,7 +265,7 @@ describe('e2e AWS AUTH', function () {

it('connects for the IAM role session', async function () {
const tokenDetails = generateIamSessionToken();
const shell = TestShell.start({
const shell = this.startTestShell({
args: [
getConnectionString(),
'--username',
9 changes: 4 additions & 5 deletions packages/e2e-tests/test/e2e-banners.spec.ts
Original file line number Diff line number Diff line change
@@ -2,17 +2,16 @@ import {
skipIfApiStrict,
startSharedTestServer,
} from '../../../testing/integration-testing-hooks';
import { TestShell } from './test-shell';
import type { TestShell } from './test-shell';

describe('e2e startup banners', function () {
skipIfApiStrict();
afterEach(TestShell.cleanup);

const testServer = startSharedTestServer();

context('without special configuration', function () {
it('shows startup warnings', async function () {
const shell = TestShell.start({
const shell = this.startTestShell({
args: [await testServer.connectionString()],
});
await shell.waitForPrompt();
@@ -30,7 +29,7 @@ describe('e2e startup banners', function () {
let helperShell: TestShell;

beforeEach(async function () {
helperShell = TestShell.start({
helperShell = this.startTestShell({
args: [await testServer.connectionString()],
});
await helperShell.waitForPrompt();
@@ -47,7 +46,7 @@ describe('e2e startup banners', function () {
});

it('shows automation notices', async function () {
const shell = TestShell.start({
const shell = this.startTestShell({
args: [await testServer.connectionString()],
});
await shell.waitForPrompt();
6 changes: 3 additions & 3 deletions packages/e2e-tests/test/e2e-bson.spec.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { expect } from 'chai';
import type { Db } from 'mongodb';
import { MongoClient } from 'mongodb';
import { bson } from '@mongosh/service-provider-core';
import { TestShell } from './test-shell';
import type { TestShell } from './test-shell';
import { startSharedTestServer } from '../../../testing/integration-testing-hooks';

describe('BSON e2e', function () {
@@ -15,7 +15,7 @@ describe('BSON e2e', function () {
beforeEach(async function () {
const connectionString = await testServer.connectionString();
dbName = `test-${Date.now()}`;
shell = TestShell.start({ args: [connectionString] });
shell = this.startTestShell({ args: [connectionString] });

client = await MongoClient.connect(connectionString, {});

@@ -30,7 +30,7 @@ describe('BSON e2e', function () {

await client.close();
});
afterEach(TestShell.cleanup);

describe('printed BSON', function () {
const outputDoc = {
ObjectId: "ObjectId('5f16b8bebe434dc98cdfc9ca')",
Loading