Skip to content

Commit dd32591

Browse files
committed
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.
1 parent 33f85ff commit dd32591

File tree

6 files changed

+31
-45
lines changed

6 files changed

+31
-45
lines changed

.evergreen/setup-env.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ fi
1313
export BASEDIR="$PWD/.evergreen"
1414
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"
1515

16-
export MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT=100000
16+
export MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING="$BASEDIR/../../testing/tests-globalconfig.conf"
17+
1718
export IS_MONGOSH_EVERGREEN_CI=1
1819
export DEBUG="mongodb*,$DEBUG"
1920

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,9 +1463,6 @@ describe('CliRepl', function () {
14631463
it('can set log max file count', async function () {
14641464
const testMaxFileCount = 123;
14651465
cliRepl.config.logMaxFileCount = testMaxFileCount;
1466-
const oldEnvironmentLimit =
1467-
process.env.MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT;
1468-
delete process.env.MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT;
14691466
await cliRepl.start(await testServer.connectionString(), {});
14701467

14711468
expect(await cliRepl.getConfig('logMaxFileCount')).equals(
@@ -1474,9 +1471,6 @@ describe('CliRepl', function () {
14741471
expect(cliRepl.logManager?._options.maxLogFileCount).equals(
14751472
testMaxFileCount
14761473
);
1477-
1478-
process.env.MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT =
1479-
oldEnvironmentLimit;
14801474
});
14811475

14821476
it('can set log compression', async function () {

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,7 @@ export class CliRepl implements MongoshIOProvider {
261261
this.shellHomeDirectory.localPath('.'),
262262
retentionDays: await this.getConfig('logRetentionDays'),
263263
gzip: await this.getConfig('logCompressionEnabled'),
264-
maxLogFileCount: +(
265-
process.env.MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT ||
266-
(await this.getConfig('logMaxFileCount'))
267-
),
264+
maxLogFileCount: await this.getConfig('logMaxFileCount'),
268265
onerror: (err: Error) => this.bus.emit('mongosh:error', err, 'log'),
269266
onwarn: (err: Error, path: string) =>
270267
this.warnAboutInaccessibleFile(err, path),

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

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ describe('e2e', function () {
14141414
startTestShell = async (...extraArgs: string[]) => {
14151415
const shell = this.startTestShell({
14161416
args: ['--nodb', ...extraArgs],
1417-
env: env,
1417+
env,
14181418
forceTerminal: true,
14191419
});
14201420
await shell.waitForPrompt();
@@ -1467,10 +1467,8 @@ describe('e2e', function () {
14671467
);
14681468
shell = this.startTestShell({
14691469
args: ['--nodb'],
1470-
env: {
1471-
...env,
1472-
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
1473-
},
1470+
env,
1471+
globalConfigPath: globalConfig,
14741472
forceTerminal: true,
14751473
});
14761474
await shell.waitForPrompt();
@@ -1524,10 +1522,8 @@ describe('e2e', function () {
15241522
await fs.writeFile(globalConfig, 'mongosh:\n disableLogging: true');
15251523
shell = this.startTestShell({
15261524
args: ['--nodb'],
1527-
env: {
1528-
...env,
1529-
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
1530-
},
1525+
env,
1526+
globalConfigPath: globalConfig,
15311527
forceTerminal: true,
15321528
});
15331529
await shell.waitForPrompt();
@@ -1545,10 +1541,8 @@ describe('e2e', function () {
15451541
await fs.writeFile(globalConfig, 'mongosh:\n disableLogging: false');
15461542
shell = this.startTestShell({
15471543
args: ['--nodb'],
1548-
env: {
1549-
...env,
1550-
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
1551-
},
1544+
env,
1545+
globalConfigPath: globalConfig,
15521546
forceTerminal: true,
15531547
});
15541548
await shell.waitForPrompt();
@@ -1580,10 +1574,8 @@ describe('e2e', function () {
15801574

15811575
shell = this.startTestShell({
15821576
args: ['--nodb'],
1583-
env: {
1584-
...env,
1585-
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
1586-
},
1577+
env,
1578+
globalConfigPath: globalConfig,
15871579
forceTerminal: true,
15881580
});
15891581
await shell.waitForPrompt();
@@ -1610,10 +1602,8 @@ describe('e2e', function () {
16101602

16111603
shell = this.startTestShell({
16121604
args: ['--nodb'],
1613-
env: {
1614-
...env,
1615-
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
1616-
},
1605+
env,
1606+
globalConfigPath: globalConfig,
16171607
forceTerminal: true,
16181608
});
16191609
await shell.waitForPrompt();
@@ -1705,10 +1695,8 @@ describe('e2e', function () {
17051695

17061696
shell = this.startTestShell({
17071697
args: ['--nodb'],
1708-
env: {
1709-
...env,
1710-
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
1711-
},
1698+
env,
1699+
globalConfigPath: globalConfig,
17121700
forceTerminal: true,
17131701
});
17141702

@@ -1774,10 +1762,8 @@ describe('e2e', function () {
17741762

17751763
shell = this.startTestShell({
17761764
args: ['--nodb'],
1777-
env: {
1778-
...env,
1779-
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
1780-
},
1765+
env,
1766+
globalConfigPath: globalConfig,
17811767
forceTerminal: true,
17821768
});
17831769

@@ -1818,11 +1804,8 @@ describe('e2e', function () {
18181804
expect(await getFilesState(paths)).to.equal('1111111111');
18191805
shell = this.startTestShell({
18201806
args: ['--nodb'],
1821-
env: {
1822-
...env,
1823-
MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT: '',
1824-
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
1825-
},
1807+
env,
1808+
globalConfigPath: globalConfig,
18261809
forceTerminal: true,
18271810
});
18281811

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface TestShellOptions {
3939
cwd?: string;
4040
forceTerminal?: boolean;
4141
consumeStdio?: boolean;
42+
globalConfigPath?: string;
4243
}
4344

4445
/**
@@ -63,6 +64,13 @@ export class TestShell {
6364
env = { ...env, MONGOSH_FORCE_TERMINAL: '1' };
6465
}
6566

67+
if (options.globalConfigPath) {
68+
env = {
69+
...env,
70+
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: options.globalConfigPath,
71+
};
72+
}
73+
6674
const args = [...options.args];
6775
if (process.env.MONGOSH_TEST_E2E_FORCE_FIPS) {
6876
args.push('--tlsFIPSMode');

testing/tests-globalconfig.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Default global configuration used by tests
2+
mongosh:
3+
logMaxFileCount: 100000

0 commit comments

Comments
 (0)