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();

0 commit comments

Comments
 (0)