Skip to content

chore(ci): improve log file collection logic #2164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .evergreen.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions .evergreen/evergreen.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .evergreen/setup-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 3 additions & 1 deletion packages/cli-repl/src/cli-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/test/e2e-analytics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
32 changes: 25 additions & 7 deletions packages/e2e-tests/test/test-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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<void> {
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();
Expand Down Expand Up @@ -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);
Loading