From 2dfcb0308b755a823fbe118fed58eed1c414fa0a Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 25 Sep 2024 14:24:43 +0200 Subject: [PATCH] chore(ci): improve log file collection logic (#2164) --- .evergreen.yml | 6 ++++ .evergreen/evergreen.yml.in | 6 ++++ .evergreen/setup-env.sh | 1 + packages/cli-repl/src/cli-repl.ts | 4 ++- packages/e2e-tests/test/e2e-analytics.spec.ts | 2 +- packages/e2e-tests/test/test-shell.ts | 32 +++++++++++++++---- 6 files changed, 42 insertions(+), 9 deletions(-) diff --git a/.evergreen.yml b/.evergreen.yml index bd10e1296..8f5f8e763 100644 --- a/.evergreen.yml +++ b/.evergreen.yml @@ -1,6 +1,12 @@ exec_timeout_secs: 10800 +pre: + - command: shell.exec + params: + shell: bash + script: | + rm -rf "$HOME/.mongodb/mongosh" post_error_fails_task: true post: - command: shell.exec diff --git a/.evergreen/evergreen.yml.in b/.evergreen/evergreen.yml.in index 13d3831ac..bf834d4fa 100644 --- a/.evergreen/evergreen.yml.in +++ b/.evergreen/evergreen.yml.in @@ -68,6 +68,12 @@ const { RELEASE_PACKAGE_MATRIX } = require('../config/release-package-matrix'); %> exec_timeout_secs: 10800 +pre: + - command: shell.exec + params: + shell: bash + script: | + rm -rf "$HOME/.mongodb/mongosh" post_error_fails_task: true post: - command: shell.exec diff --git a/.evergreen/setup-env.sh b/.evergreen/setup-env.sh index 3263e5ea3..0100a0c01 100755 --- a/.evergreen/setup-env.sh +++ b/.evergreen/setup-env.sh @@ -4,6 +4,7 @@ set -x export BASEDIR="$PWD/.evergreen" 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" +export MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT=100000 export IS_MONGOSH_EVERGREEN_CI=1 export DEBUG="mongodb*,$DEBUG" diff --git a/packages/cli-repl/src/cli-repl.ts b/packages/cli-repl/src/cli-repl.ts index 9de688c44..d1784eb7c 100644 --- a/packages/cli-repl/src/cli-repl.ts +++ b/packages/cli-repl/src/cli-repl.ts @@ -192,7 +192,9 @@ export class CliRepl implements MongoshIOProvider { this.logManager = new MongoLogManager({ directory: this.shellHomeDirectory.localPath('.'), retentionDays: 30, - maxLogFileCount: 100, + maxLogFileCount: +( + process.env.MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT || 100 + ), onerror: (err: Error) => this.bus.emit('mongosh:error', err, 'log'), onwarn: (err: Error, path: string) => this.warnAboutInaccessibleFile(err, path), diff --git a/packages/e2e-tests/test/e2e-analytics.spec.ts b/packages/e2e-tests/test/e2e-analytics.spec.ts index 27d470acd..f660c5d84 100644 --- a/packages/e2e-tests/test/e2e-analytics.spec.ts +++ b/packages/e2e-tests/test/e2e-analytics.spec.ts @@ -13,7 +13,7 @@ describe('e2e Analytics Node', function () { { args: ['--replSet', replSetName] } ); - after(TestShell.cleanup); + afterEach(TestShell.cleanup); before(async function () { if (process.env.MONGOSH_TEST_FORCE_API_STRICT) { diff --git a/packages/e2e-tests/test/test-shell.ts b/packages/e2e-tests/test/test-shell.ts index 4474b07a7..ada66d234 100644 --- a/packages/e2e-tests/test/test-shell.ts +++ b/packages/e2e-tests/test/test-shell.ts @@ -115,16 +115,31 @@ export class TestShell { await Promise.all(exitPromises); } + debugInformation() { + return { + pid: this.process.pid, + output: this.output, + rawOutput: this.rawOutput, + exitCode: this.process.exitCode, + signal: this.process.signalCode, + }; + } + + static async cleanupAfterAll(): Promise { + let foundOpenShells = false; + for (const shell of TestShell._openShells) { + foundOpenShells = true; + console.error(shell.debugInformation()); + } + await TestShell.killall(); + if (foundOpenShells) + throw new Error('Open shells at end of test discovered!'); + } + static async cleanup(this: Mocha.Context): Promise { if (this.currentTest?.state === 'failed') { for (const shell of TestShell._openShells) { - console.error({ - pid: shell.process.pid, - output: shell.output, - rawOutput: shell.rawOutput, - exitCode: shell.process.exitCode, - signal: shell.process.signalCode, - }); + console.error(shell.debugInformation()); } } await TestShell.killall(); @@ -321,3 +336,6 @@ export class TestShell { return match.groups!.logId; } } + +// If any shells remain at the end of the script, print their full output +globalThis?.after('ensure no hanging shells', TestShell.cleanupAfterAll);