Skip to content

Commit 061dbb5

Browse files
authored
chore(cli-repl): print test shell output for failing e2e tests (#799)
This is just to get better debugging in the future for flaky tests in general.
1 parent 29dd4d0 commit 061dbb5

File tree

9 files changed

+27
-19
lines changed

9 files changed

+27
-19
lines changed

packages/cli-repl/test/e2e-analytics.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ describe('e2e Analytics', () => {
1212
[ '--single', '--replSet', replSetName ]
1313
);
1414

15-
after(async() => {
16-
await TestShell.killall();
17-
});
15+
after(TestShell.cleanup);
1816

1917
before(async() => {
2018
const rsConfig = {

packages/cli-repl/test/e2e-auth.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ describe('Auth e2e', function() {
103103
await db.command({ dropAllUsersFromDatabase: 1 });
104104

105105
client.close();
106-
await TestShell.killall();
107106
});
107+
afterEach(TestShell.cleanup);
108108

109109
describe('user management', () => {
110110
describe('createUser', async() => {
@@ -991,7 +991,7 @@ describe('Auth e2e', function() {
991991
await db.command({ dropAllUsersFromDatabase: 1 });
992992

993993
client.close();
994-
await TestShell.killall();
995994
});
995+
afterEach(TestShell.cleanup);
996996
});
997997
});

packages/cli-repl/test/e2e-aws.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ describe('e2e AWS AUTH', () => {
8989
.replace('arn:aws:iam::', 'arn:aws:sts::')}/*`;
9090
});
9191

92-
afterEach(async() => {
93-
await TestShell.killall();
94-
});
92+
afterEach(TestShell.cleanup);
9593

9694
context('without environment variables being present', () => {
9795
context('specifying explicit parameters', () => {

packages/cli-repl/test/e2e-bson.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ describe('BSON e2e', function() {
3333
await db.dropDatabase();
3434

3535
await client.close();
36-
await TestShell.killall();
3736
});
37+
afterEach(TestShell.cleanup);
3838
describe('printed BSON', () => {
3939
const outputDoc = {
4040
ObjectId: 'ObjectId("5f16b8bebe434dc98cdfc9ca")',

packages/cli-repl/test/e2e-direct.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { expect } from 'chai';
44
import { TestShell } from './test-shell';
55

66
describe('e2e direct connection', () => {
7-
afterEach(async() => await TestShell.killall());
7+
afterEach(TestShell.cleanup);
88

99
context('to a replica set', async() => {
1010
const replSetId = 'replset';

packages/cli-repl/test/e2e-fle.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ describe('FLE tests', () => {
3232
const client = await MongoClient.connect(await testServer.connectionString(), {});
3333
await client.db(dbname).dropDatabase();
3434
await client.close();
35-
await TestShell.killall();
3635
});
36+
afterEach(TestShell.cleanup);
3737

3838
context('with AWS KMS', () => {
3939
const accessKeyId = 'SxHpYMUtB1CEVg9tX0N1';

packages/cli-repl/test/e2e-tls.spec.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ describe('e2e TLS', () => {
2727
assert((await fs.stat(CRL_INCLUDING_SERVER)).isFile());
2828
});
2929

30-
afterEach(async() => {
31-
await TestShell.killall();
32-
});
30+
afterEach(TestShell.cleanup);
3331

3432
context('for server < 4.2', () => {
3533
skipIfEnvServerVersion('>= 4.2');
@@ -65,8 +63,10 @@ describe('e2e TLS', () => {
6563
});
6664
await shell.waitForPrompt();
6765
await shell.executeLine('db.shutdownServer({ force: true })');
68-
await TestShell.killall();
66+
shell.kill();
67+
await shell.waitForExit();
6968
});
69+
afterEach(TestShell.cleanup);
7070

7171
const server = startTestServer(
7272
'not-shared', '--hostname', 'localhost',
@@ -166,8 +166,10 @@ describe('e2e TLS', () => {
166166
});
167167
await shell.waitForPrompt();
168168
await shell.executeLine('db.shutdownServer({ force: true })');
169-
await TestShell.killall();
169+
shell.kill();
170+
await shell.waitForExit();
170171
});
172+
afterEach(TestShell.cleanup);
171173

172174
const server = startTestServer(
173175
'not-shared', '--hostname', 'localhost',

packages/cli-repl/test/e2e.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { readReplLogfile, hasNodeBug38314 } from './repl-helpers';
1313
describe('e2e', function() {
1414
const testServer = startTestServer('shared');
1515

16-
afterEach(async() => await TestShell.killall());
16+
afterEach(TestShell.cleanup);
1717

1818
describe('--version', () => {
1919
it('shows version', async() => {
@@ -654,8 +654,8 @@ describe('e2e', function() {
654654
};
655655
});
656656

657-
afterEach(async() => {
658-
await TestShell.killall();
657+
afterEach(async function() {
658+
await TestShell.killall.call(this);
659659
try {
660660
await promisify(rimraf)(homedir);
661661
} catch (err) {

packages/cli-repl/test/test-shell.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type Mocha from 'mocha';
12
import assert from 'assert';
23
import { ChildProcess, spawn } from 'child_process';
34
import { once } from 'events';
@@ -74,6 +75,15 @@ export class TestShell {
7475
await Promise.all(exitPromises);
7576
}
7677

78+
static async cleanup(this: Mocha.Context): Promise<void> {
79+
if (this.currentTest?.state === 'failed') {
80+
for (const shell of TestShell._openShells) {
81+
console.error({ pid: shell.process.pid, output: shell.output, rawOutput: shell.rawOutput });
82+
}
83+
}
84+
await TestShell.killall();
85+
}
86+
7787
private _process: ChildProcess;
7888

7989
private _output: string;

0 commit comments

Comments
 (0)