From f1ef7ff6788be94658d4695e9bc793a5bd7ae92d Mon Sep 17 00:00:00 2001 From: gagik Date: Wed, 12 Feb 2025 11:21:05 +0100 Subject: [PATCH] chore(tests): use global config instead of MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT environment variable MONGOSH-2009 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. --- .evergreen/setup-env.sh | 3 +- packages/cli-repl/src/cli-repl.spec.ts | 6 --- packages/cli-repl/src/cli-repl.ts | 5 +-- packages/e2e-tests/test/e2e.spec.ts | 58 +++++++++----------------- packages/e2e-tests/test/test-shell.ts | 8 ++++ testing/tests-globalconfig.conf | 3 ++ 6 files changed, 33 insertions(+), 50 deletions(-) create mode 100644 testing/tests-globalconfig.conf diff --git a/.evergreen/setup-env.sh b/.evergreen/setup-env.sh index fd555dba72..7526c19cc2 100755 --- a/.evergreen/setup-env.sh +++ b/.evergreen/setup-env.sh @@ -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" diff --git a/packages/cli-repl/src/cli-repl.spec.ts b/packages/cli-repl/src/cli-repl.spec.ts index 4d55703dbd..0146499e41 100644 --- a/packages/cli-repl/src/cli-repl.spec.ts +++ b/packages/cli-repl/src/cli-repl.spec.ts @@ -1482,9 +1482,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( @@ -1493,9 +1490,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 () { diff --git a/packages/cli-repl/src/cli-repl.ts b/packages/cli-repl/src/cli-repl.ts index 912603c49c..053d7519d5 100644 --- a/packages/cli-repl/src/cli-repl.ts +++ b/packages/cli-repl/src/cli-repl.ts @@ -262,10 +262,7 @@ export class CliRepl implements MongoshIOProvider { prefix: customLogLocation ? 'mongosh_' : undefined, 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), diff --git a/packages/e2e-tests/test/e2e.spec.ts b/packages/e2e-tests/test/e2e.spec.ts index 221f347adf..019e0d78d9 100644 --- a/packages/e2e-tests/test/e2e.spec.ts +++ b/packages/e2e-tests/test/e2e.spec.ts @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -1742,10 +1732,8 @@ describe('e2e', function () { shell = this.startTestShell({ args: ['--nodb'], - env: { - ...env, - MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig, - }, + env, + globalConfigPath: globalConfig, forceTerminal: true, }); @@ -1811,10 +1799,8 @@ describe('e2e', function () { shell = this.startTestShell({ args: ['--nodb'], - env: { - ...env, - MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig, - }, + env, + globalConfigPath: globalConfig, forceTerminal: true, }); @@ -1864,11 +1850,8 @@ describe('e2e', function () { 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, }); @@ -1900,11 +1883,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, }); diff --git a/packages/e2e-tests/test/test-shell.ts b/packages/e2e-tests/test/test-shell.ts index 3a5d870b82..7024255e1d 100644 --- a/packages/e2e-tests/test/test-shell.ts +++ b/packages/e2e-tests/test/test-shell.ts @@ -39,6 +39,7 @@ export interface TestShellOptions { cwd?: string; forceTerminal?: boolean; consumeStdio?: boolean; + globalConfigPath?: string; } /** @@ -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'); diff --git a/testing/tests-globalconfig.conf b/testing/tests-globalconfig.conf new file mode 100644 index 0000000000..e90115218f --- /dev/null +++ b/testing/tests-globalconfig.conf @@ -0,0 +1,3 @@ +# Default global configuration used by tests +mongosh: + logMaxFileCount: 100000 \ No newline at end of file