Skip to content

Commit

Permalink
chore(tests): use logMaxFileCount instead of a environment variable…
Browse files Browse the repository at this point in the history
… in tests MONGOSH-2009 (#2366)

Previously we relied on MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT for setting max log files. Now we can do so by defining a global config for tests.
  • Loading branch information
gagik authored Feb 12, 2025
1 parent 08715fa commit a5e517c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .evergreen/setup-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ fi
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:$TOOLCHAIN_PATH:$PATH"

export MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT=100000
export MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING="$BASEDIR/../../testing/tests-globalconfig.conf"

export IS_MONGOSH_EVERGREEN_CI=1
export DEBUG="mongodb*,$DEBUG"

Expand Down
6 changes: 0 additions & 6 deletions packages/cli-repl/src/cli-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1463,9 +1463,6 @@ describe('CliRepl', function () {
it('can set log max file count', async function () {
const testMaxFileCount = 123;
cliRepl.config.logMaxFileCount = testMaxFileCount;
const oldEnvironmentLimit =
process.env.MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT;
delete process.env.MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT;
await cliRepl.start(await testServer.connectionString(), {});

expect(await cliRepl.getConfig('logMaxFileCount')).equals(
Expand All @@ -1474,9 +1471,6 @@ describe('CliRepl', function () {
expect(cliRepl.logManager?._options.maxLogFileCount).equals(
testMaxFileCount
);

process.env.MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT =
oldEnvironmentLimit;
});

it('can set log compression', async function () {
Expand Down
5 changes: 1 addition & 4 deletions packages/cli-repl/src/cli-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,7 @@ export class CliRepl implements MongoshIOProvider {
this.shellHomeDirectory.localPath('.'),
retentionDays: await this.getConfig('logRetentionDays'),
gzip: await this.getConfig('logCompressionEnabled'),
maxLogFileCount: +(
process.env.MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT ||
(await this.getConfig('logMaxFileCount'))
),
maxLogFileCount: await this.getConfig('logMaxFileCount'),
onerror: (err: Error) => this.bus.emit('mongosh:error', err, 'log'),
onwarn: (err: Error, path: string) =>
this.warnAboutInaccessibleFile(err, path),
Expand Down
51 changes: 17 additions & 34 deletions packages/e2e-tests/test/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ describe('e2e', function () {
startTestShell = async (...extraArgs: string[]) => {
const shell = this.startTestShell({
args: ['--nodb', ...extraArgs],
env: env,
env,
forceTerminal: true,
});
await shell.waitForPrompt();
Expand Down Expand Up @@ -1467,10 +1467,8 @@ describe('e2e', function () {
);
shell = this.startTestShell({
args: ['--nodb'],
env: {
...env,
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
},
env,
globalConfigPath: globalConfig,
forceTerminal: true,
});
await shell.waitForPrompt();
Expand Down Expand Up @@ -1524,10 +1522,8 @@ describe('e2e', function () {
await fs.writeFile(globalConfig, 'mongosh:\n disableLogging: true');
shell = this.startTestShell({
args: ['--nodb'],
env: {
...env,
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
},
env,
globalConfigPath: globalConfig,
forceTerminal: true,
});
await shell.waitForPrompt();
Expand All @@ -1545,10 +1541,8 @@ describe('e2e', function () {
await fs.writeFile(globalConfig, 'mongosh:\n disableLogging: false');
shell = this.startTestShell({
args: ['--nodb'],
env: {
...env,
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
},
env,
globalConfigPath: globalConfig,
forceTerminal: true,
});
await shell.waitForPrompt();
Expand Down Expand Up @@ -1580,10 +1574,8 @@ describe('e2e', function () {

shell = this.startTestShell({
args: ['--nodb'],
env: {
...env,
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
},
env,
globalConfigPath: globalConfig,
forceTerminal: true,
});
await shell.waitForPrompt();
Expand All @@ -1610,10 +1602,8 @@ describe('e2e', function () {

shell = this.startTestShell({
args: ['--nodb'],
env: {
...env,
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
},
env,
globalConfigPath: globalConfig,
forceTerminal: true,
});
await shell.waitForPrompt();
Expand Down Expand Up @@ -1705,10 +1695,8 @@ describe('e2e', function () {

shell = this.startTestShell({
args: ['--nodb'],
env: {
...env,
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
},
env,
globalConfigPath: globalConfig,
forceTerminal: true,
});

Expand Down Expand Up @@ -1774,10 +1762,8 @@ describe('e2e', function () {

shell = this.startTestShell({
args: ['--nodb'],
env: {
...env,
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
},
env,
globalConfigPath: globalConfig,
forceTerminal: true,
});

Expand Down Expand Up @@ -1818,11 +1804,8 @@ describe('e2e', function () {
expect(await getFilesState(paths)).to.equal('1111111111');
shell = this.startTestShell({
args: ['--nodb'],
env: {
...env,
MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT: '',
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
},
env,
globalConfigPath: globalConfig,
forceTerminal: true,
});

Expand Down
8 changes: 8 additions & 0 deletions packages/e2e-tests/test/test-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface TestShellOptions {
cwd?: string;
forceTerminal?: boolean;
consumeStdio?: boolean;
globalConfigPath?: string;
}

/**
Expand All @@ -63,6 +64,13 @@ export class TestShell {
env = { ...env, MONGOSH_FORCE_TERMINAL: '1' };
}

if (options.globalConfigPath) {
env = {
...env,
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: options.globalConfigPath,
};
}

const args = [...options.args];
if (process.env.MONGOSH_TEST_E2E_FORCE_FIPS) {
args.push('--tlsFIPSMode');
Expand Down
3 changes: 3 additions & 0 deletions testing/tests-globalconfig.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Default global configuration used by tests
mongosh:
logMaxFileCount: 100000

0 comments on commit a5e517c

Please sign in to comment.