Skip to content

Commit 2dfcb03

Browse files
authored
chore(ci): improve log file collection logic (#2164)
1 parent a07d2a7 commit 2dfcb03

File tree

6 files changed

+42
-9
lines changed

6 files changed

+42
-9
lines changed

.evergreen.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11

22
exec_timeout_secs: 10800
33

4+
pre:
5+
- command: shell.exec
6+
params:
7+
shell: bash
8+
script: |
9+
rm -rf "$HOME/.mongodb/mongosh"
410
post_error_fails_task: true
511
post:
612
- command: shell.exec

.evergreen/evergreen.yml.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ const { RELEASE_PACKAGE_MATRIX } = require('../config/release-package-matrix');
6868
%>
6969
exec_timeout_secs: 10800
7070

71+
pre:
72+
- command: shell.exec
73+
params:
74+
shell: bash
75+
script: |
76+
rm -rf "$HOME/.mongodb/mongosh"
7177
post_error_fails_task: true
7278
post:
7379
- command: shell.exec

.evergreen/setup-env.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set -x
44
export BASEDIR="$PWD/.evergreen"
55
export PATH="/cygdrive/c/python/Python311/Scripts:/cygdrive/c/python/Python311:/cygdrive/c/Python311/Scripts:/cygdrive/c/Python311:/opt/python/3.6/bin:$BASEDIR/mingit/cmd:$BASEDIR/mingit/mingw64/libexec/git-core:$BASEDIR/git-2:$BASEDIR/npm-10/node_modules/.bin:$BASEDIR/node-v$NODE_JS_VERSION-win-x64:/opt/java/jdk16/bin:/opt/chefdk/gitbin:/cygdrive/c/cmake/bin:/opt/mongodbtoolchain/v3/bin:$PATH"
66

7+
export MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT=100000
78
export IS_MONGOSH_EVERGREEN_CI=1
89
export DEBUG="mongodb*,$DEBUG"
910

packages/cli-repl/src/cli-repl.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ export class CliRepl implements MongoshIOProvider {
192192
this.logManager = new MongoLogManager({
193193
directory: this.shellHomeDirectory.localPath('.'),
194194
retentionDays: 30,
195-
maxLogFileCount: 100,
195+
maxLogFileCount: +(
196+
process.env.MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT || 100
197+
),
196198
onerror: (err: Error) => this.bus.emit('mongosh:error', err, 'log'),
197199
onwarn: (err: Error, path: string) =>
198200
this.warnAboutInaccessibleFile(err, path),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('e2e Analytics Node', function () {
1313
{ args: ['--replSet', replSetName] }
1414
);
1515

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

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

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,31 @@ export class TestShell {
115115
await Promise.all(exitPromises);
116116
}
117117

118+
debugInformation() {
119+
return {
120+
pid: this.process.pid,
121+
output: this.output,
122+
rawOutput: this.rawOutput,
123+
exitCode: this.process.exitCode,
124+
signal: this.process.signalCode,
125+
};
126+
}
127+
128+
static async cleanupAfterAll(): Promise<void> {
129+
let foundOpenShells = false;
130+
for (const shell of TestShell._openShells) {
131+
foundOpenShells = true;
132+
console.error(shell.debugInformation());
133+
}
134+
await TestShell.killall();
135+
if (foundOpenShells)
136+
throw new Error('Open shells at end of test discovered!');
137+
}
138+
118139
static async cleanup(this: Mocha.Context): Promise<void> {
119140
if (this.currentTest?.state === 'failed') {
120141
for (const shell of TestShell._openShells) {
121-
console.error({
122-
pid: shell.process.pid,
123-
output: shell.output,
124-
rawOutput: shell.rawOutput,
125-
exitCode: shell.process.exitCode,
126-
signal: shell.process.signalCode,
127-
});
142+
console.error(shell.debugInformation());
128143
}
129144
}
130145
await TestShell.killall();
@@ -321,3 +336,6 @@ export class TestShell {
321336
return match.groups!.logId;
322337
}
323338
}
339+
340+
// If any shells remain at the end of the script, print their full output
341+
globalThis?.after('ensure no hanging shells', TestShell.cleanupAfterAll);

0 commit comments

Comments
 (0)