Skip to content

Commit 426e2c9

Browse files
committed
Refactored TestShell to ensure killAll is called
1 parent a520eb1 commit 426e2c9

15 files changed

+106
-61
lines changed

packages/e2e-tests/test/e2e-analytics.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
22
import { startTestCluster } from '../../../testing/integration-testing-hooks';
33
import { eventually } from '../../../testing/eventually';
4-
import { TestShell } from './test-shell';
4+
import { cleanTestShellsAfter, TestShell } from './test-shell';
55

66
describe('e2e Analytics Node', function () {
77
const replSetName = 'replicaSet';
@@ -13,7 +13,7 @@ describe('e2e Analytics Node', function () {
1313
{ args: ['--replSet', replSetName] }
1414
);
1515

16-
after(TestShell.cleanup);
16+
cleanTestShellsAfter();
1717

1818
before(async function () {
1919
if (process.env.MONGOSH_TEST_FORCE_API_STRICT) {

packages/e2e-tests/test/e2e-auth.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from 'chai';
22
import type { Db, Document, MongoClientOptions } from 'mongodb';
33
import { MongoClient } from 'mongodb';
44
import { eventually } from '../../../testing/eventually';
5-
import { TestShell } from './test-shell';
5+
import { cleanTestShellsAfterEach, TestShell } from './test-shell';
66
import {
77
skipIfApiStrict,
88
startSharedTestServer,
@@ -107,6 +107,8 @@ describe('Auth e2e', function () {
107107
let examplePrivilege2: Document;
108108

109109
describe('with regular URI', function () {
110+
cleanTestShellsAfterEach();
111+
110112
beforeEach(async function () {
111113
const connectionString = await testServer.connectionString();
112114
dbName = `test-${Date.now()}`;
@@ -137,7 +139,6 @@ describe('Auth e2e', function () {
137139

138140
await client.close();
139141
});
140-
afterEach(TestShell.cleanup);
141142

142143
describe('user management', function () {
143144
describe('createUser', function () {
@@ -1144,6 +1145,7 @@ describe('Auth e2e', function () {
11441145

11451146
await client.close();
11461147
});
1147-
afterEach(TestShell.cleanup);
1148+
1149+
cleanTestShellsAfterEach();
11481150
});
11491151
});

packages/e2e-tests/test/e2e-aws.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai';
22
import { spawnSync } from 'child_process';
3-
import { TestShell } from './test-shell';
3+
import { cleanTestShellsAfterEach, TestShell } from './test-shell';
44

55
function assertEnvVariable(variableName: string): string {
66
if (process.env.MONGOSH_TEST_FORCE_API_STRICT) {
@@ -84,6 +84,8 @@ function getConnectionString(username?: string, password?: string): string {
8484
}
8585

8686
describe('e2e AWS AUTH', function () {
87+
cleanTestShellsAfterEach();
88+
8789
this.timeout(60_000); // AWS auth tests can take longer than the default timeout in CI
8890
let expectedAssumedRole: string;
8991

@@ -117,8 +119,6 @@ describe('e2e AWS AUTH', function () {
117119
).replace('arn:aws:iam::', 'arn:aws:sts::')}/*`;
118120
});
119121

120-
afterEach(TestShell.cleanup);
121-
122122
context('without environment variables being present', function () {
123123
context('specifying explicit parameters', function () {
124124
it('connects with access key and secret', async function () {

packages/e2e-tests/test/e2e-banners.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import {
22
skipIfApiStrict,
33
startSharedTestServer,
44
} from '../../../testing/integration-testing-hooks';
5-
import { TestShell } from './test-shell';
5+
import { cleanTestShellsAfterEach, TestShell } from './test-shell';
66

77
describe('e2e startup banners', function () {
88
skipIfApiStrict();
9-
afterEach(TestShell.cleanup);
9+
cleanTestShellsAfterEach();
1010

1111
const testServer = startSharedTestServer();
1212

packages/e2e-tests/test/e2e-bson.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { expect } from 'chai';
22
import type { Db } from 'mongodb';
33
import { MongoClient } from 'mongodb';
44
import { bson } from '@mongosh/service-provider-core';
5-
import { TestShell } from './test-shell';
5+
import { cleanTestShellsAfterEach, TestShell } from './test-shell';
66
import { startSharedTestServer } from '../../../testing/integration-testing-hooks';
77

88
describe('BSON e2e', function () {
9+
cleanTestShellsAfterEach();
10+
911
const testServer = startSharedTestServer();
1012
let db: Db;
1113
let client: MongoClient;
@@ -30,7 +32,7 @@ describe('BSON e2e', function () {
3032

3133
await client.close();
3234
});
33-
afterEach(TestShell.cleanup);
35+
3436
describe('printed BSON', function () {
3537
const outputDoc = {
3638
ObjectId: "ObjectId('5f16b8bebe434dc98cdfc9ca')",

packages/e2e-tests/test/e2e-direct.spec.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import {
55
} from '../../../testing/integration-testing-hooks';
66
import { eventually } from '../../../testing/eventually';
77
import { expect } from 'chai';
8-
import { TestShell } from './test-shell';
8+
import { TestShell, cleanTestShellsAfterEach } from './test-shell';
99

1010
describe('e2e direct connection', function () {
1111
skipIfApiStrict();
12-
afterEach(TestShell.cleanup);
12+
cleanTestShellsAfterEach();
1313

1414
const tabtab = async (shell: TestShell) => {
1515
await new Promise((resolve) => setTimeout(resolve, 400));
@@ -82,11 +82,6 @@ describe('e2e direct connection', function () {
8282
await shell.executeLine('db.testcollection.insertOne({})');
8383
shell.writeInputLine('exit');
8484
});
85-
after(async function () {
86-
const shell = TestShell.start({ args: [await rs0.connectionString()] });
87-
await shell.executeLine(`db.getSiblingDB("${dbname}").dropDatabase()`);
88-
shell.writeInputLine('exit');
89-
});
9085

9186
context('connecting to secondary members directly', function () {
9287
it('works when specifying a connection string', async function () {

packages/e2e-tests/test/e2e-editor.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from 'chai';
22
import path from 'path';
33
import { promises as fs } from 'fs';
44
import { eventually } from '../../../testing/eventually';
5-
import { TestShell } from './test-shell';
5+
import { cleanTestShellsAfterEach, TestShell } from './test-shell';
66
import {
77
useTmpdir,
88
fakeExternalEditor,
@@ -15,6 +15,8 @@ describe('external editor e2e', function () {
1515
let env: Record<string, string>;
1616
let shell: TestShell;
1717

18+
cleanTestShellsAfterEach();
19+
1820
beforeEach(async function () {
1921
const homeInfo = setTemporaryHomeDirectory();
2022

@@ -42,7 +44,6 @@ describe('external editor e2e', function () {
4244
});
4345

4446
afterEach(async function () {
45-
await TestShell.killall.call(this);
4647
try {
4748
await fs.rm(homedir, { recursive: true, force: true });
4849
} catch (err: any) {

packages/e2e-tests/test/e2e-fle.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai';
22
import { MongoClient } from 'mongodb';
3-
import { TestShell } from './test-shell';
3+
import { cleanTestShellsAfterEach, TestShell } from './test-shell';
44
import { eventually } from '../../../testing/eventually';
55
import {
66
startTestServer,
@@ -16,6 +16,8 @@ import { inspect } from 'util';
1616
import path from 'path';
1717

1818
describe('FLE tests', function () {
19+
cleanTestShellsAfterEach();
20+
1921
const testServer = startTestServer('e2e-fle', {
2022
topology: 'replset',
2123
secondaries: 0,
@@ -56,7 +58,6 @@ describe('FLE tests', function () {
5658
await client.db(dbname).dropDatabase();
5759
await client.close();
5860
});
59-
afterEach(TestShell.cleanup);
6061

6162
function* awsTestCases() {
6263
for (const useApiStrict of [false, true]) {

packages/e2e-tests/test/e2e-oidc.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import { promises as fs } from 'fs';
77
import type { OIDCMockProviderConfig } from '@mongodb-js/oidc-mock-provider';
88
import { OIDCMockProvider } from '@mongodb-js/oidc-mock-provider';
9-
import { TestShell } from './test-shell';
9+
import { cleanTestShellsAfterEach, TestShell } from './test-shell';
1010
import path from 'path';
1111
import { expect } from 'chai';
1212
import { createServer as createHTTPSServer } from 'https';
@@ -30,6 +30,7 @@ import {
3030
* happens in isolation.
3131
*/
3232
describe('OIDC auth e2e', function () {
33+
cleanTestShellsAfterEach();
3334
skipIfApiStrict(); // connectionStatus is unversioned.
3435

3536
let getTokenPayload: typeof oidcMockProviderConfig.getTokenPayload;
@@ -164,8 +165,6 @@ describe('OIDC auth e2e', function () {
164165
]);
165166
});
166167

167-
afterEach(TestShell.cleanup);
168-
169168
async function verifyUser(
170169
shell: TestShell,
171170
username: string,

packages/e2e-tests/test/e2e-proxy.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
startSharedTestServer,
1212
startTestServer,
1313
} from '../../../testing/integration-testing-hooks';
14-
import { TestShell } from './test-shell';
14+
import { cleanTestShellsAfterEach, TestShell } from './test-shell';
1515
import type { Server as HTTPSServer } from 'https';
1616
import { createServer as createHTTPSServer } from 'https';
1717
import {
@@ -40,7 +40,7 @@ describe('e2e proxy support', function () {
4040
skipIfApiStrict();
4141
skipIfEnvServerVersion('< 7.0');
4242

43-
afterEach(TestShell.cleanup);
43+
cleanTestShellsAfterEach();
4444

4545
const tmpdir = useTmpdir();
4646
const testServer = startSharedTestServer();

packages/e2e-tests/test/e2e-snapshot.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
skipIfApiStrict,
33
startSharedTestServer,
44
} from '../../../testing/integration-testing-hooks';
5-
import { TestShell } from './test-shell';
5+
import { cleanTestShellsAfterEach, TestShell } from './test-shell';
66
import { expect } from 'chai';
77

88
const setDifference = <T>(a: T[], b: T[]) => a.filter((e) => !b.includes(e));
@@ -17,7 +17,8 @@ const commonPrefix = (a: string, b: string): string =>
1717

1818
describe('e2e snapshot support', function () {
1919
skipIfApiStrict();
20-
afterEach(TestShell.cleanup);
20+
21+
cleanTestShellsAfterEach();
2122

2223
const testServer = startSharedTestServer();
2324

packages/e2e-tests/test/e2e-snippet.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { promises as fs } from 'fs';
22
import path from 'path';
33
import { expect } from 'chai';
4-
import { TestShell } from './test-shell';
4+
import { cleanTestShellsAfterEach, TestShell } from './test-shell';
55
import { useTmpdir } from './repl-helpers';
66
import { eventually } from '../../../testing/eventually';
77

88
describe('snippet integration tests', function () {
9+
cleanTestShellsAfterEach();
10+
911
this.timeout(120_000);
1012
const tmpdir = useTmpdir();
1113

@@ -44,7 +46,6 @@ describe('snippet integration tests', function () {
4446
{ recursive: true }
4547
);
4648
});
47-
afterEach(TestShell.cleanup);
4849

4950
it('allows managing snippets', async function () {
5051
shell.writeInputLine('snippet install analyze-schema');

packages/e2e-tests/test/e2e-tls.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
getCertPath,
1010
connectionStringWithLocalhost,
1111
} from './repl-helpers';
12-
import { TestShell } from './test-shell';
12+
import { cleanTestShellsAfterEach, TestShell } from './test-shell';
1313

1414
const CA_CERT = getCertPath('ca.crt');
1515
const NON_CA_CERT = getCertPath('non-ca.crt');
@@ -30,6 +30,8 @@ const CRL_INCLUDING_SERVER = getCertPath('ca-server.crl');
3030
* and compliance with user-specified behavior that is specific to TLS connectivity.
3131
*/
3232
describe('e2e TLS', function () {
33+
cleanTestShellsAfterEach();
34+
3335
let homedir: string;
3436
let env: Record<string, string>;
3537
let logBasePath: string;
@@ -64,7 +66,6 @@ describe('e2e TLS', function () {
6466
console.error('Could not remove fake home directory:', err);
6567
}
6668
});
67-
afterEach(TestShell.cleanup);
6869

6970
context(
7071
'connecting without client cert to server with valid cert',
@@ -87,7 +88,6 @@ describe('e2e TLS', function () {
8788
shell.kill();
8889
await shell.waitForExit();
8990
});
90-
afterEach(TestShell.cleanup);
9191

9292
const server = startTestServer('e2e-tls-no-cli-valid-srv', {
9393
args: [
@@ -323,8 +323,6 @@ describe('e2e TLS', function () {
323323
await shell.executeLine('db.shutdownServer({ force: true })');
324324
shell.kill();
325325
await shell.waitForExit();
326-
327-
await TestShell.cleanup.call(this);
328326
});
329327

330328
const server = startTestServer('e2e-tls-valid-cli-valid-srv', {
@@ -625,7 +623,6 @@ describe('e2e TLS', function () {
625623
});
626624
await shell.waitForPrompt();
627625
await shell.executeLine('db.shutdownServer({ force: true })');
628-
await TestShell.killall();
629626
});
630627

631628
const server = startTestServer('e2e-tls-invalid-srv', {

packages/e2e-tests/test/e2e.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect } from 'chai';
33
import type { Db } from 'mongodb';
44
import { MongoClient } from 'mongodb';
55
import { eventually } from '../../../testing/eventually';
6-
import { TestShell } from './test-shell';
6+
import { cleanTestShellsAfterEach, TestShell } from './test-shell';
77
import {
88
skipIfServerVersion,
99
startSharedTestServer,
@@ -29,7 +29,7 @@ const jsContextFlagCombinations: `--jsContext=${'plain-vm' | 'repl'}`[][] = [
2929
describe('e2e', function () {
3030
const testServer = startSharedTestServer();
3131

32-
afterEach(TestShell.cleanup);
32+
cleanTestShellsAfterEach();
3333

3434
describe('--version', function () {
3535
it('shows version', async function () {
@@ -1378,7 +1378,6 @@ describe('e2e', function () {
13781378
});
13791379

13801380
afterEach(async function () {
1381-
await TestShell.killall.call(this);
13821381
try {
13831382
await fs.rm(homedir, { recursive: true, force: true });
13841383
} catch (err: any) {

0 commit comments

Comments
 (0)