Skip to content

Commit 6d8a794

Browse files
committed
tests: add end to end deletion test
1 parent cc82c07 commit 6d8a794

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,58 @@ describe('e2e', function () {
17471747
});
17481748
});
17491749

1750+
describe('with custom log retention max file count', function () {
1751+
const customLogDir = useTmpdir();
1752+
1753+
it('should delete files once it is above the max file count limit', async function () {
1754+
const globalConfig = path.join(homedir, 'globalconfig.conf');
1755+
await fs.writeFile(
1756+
globalConfig,
1757+
`mongosh:\n logLocation: ${JSON.stringify(
1758+
customLogDir.path
1759+
)}\n logMaxFileCount: 4`
1760+
);
1761+
const paths: string[] = [];
1762+
const offset = Math.floor(Date.now() / 1000);
1763+
1764+
// Create 10 log files
1765+
for (let i = 9; i >= 0; i--) {
1766+
const filename = path.join(
1767+
customLogDir.path,
1768+
ObjectId.createFromTime(offset - i).toHexString() + '_log'
1769+
);
1770+
await fs.writeFile(filename, '');
1771+
paths.push(filename);
1772+
}
1773+
1774+
// All 10 existing log files exist.
1775+
expect(await getFilesState(paths)).to.equal('1111111111');
1776+
shell = this.startTestShell({
1777+
args: ['--nodb'],
1778+
env: {
1779+
...env,
1780+
MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT: '',
1781+
MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING: globalConfig,
1782+
},
1783+
forceTerminal: true,
1784+
});
1785+
1786+
await shell.waitForPrompt();
1787+
1788+
// Add the newly created log to the file list.
1789+
paths.push(
1790+
path.join(customLogDir.path, `${shell.logId as string}_log`)
1791+
);
1792+
1793+
expect(
1794+
await shell.executeLine('config.get("logMaxFileCount")')
1795+
).contains('4');
1796+
1797+
// Expect 7 files to be deleted and 4 to remain (including the new log file)
1798+
expect(await getFilesState(paths)).to.equal('00000001111');
1799+
});
1800+
});
1801+
17501802
it('creates a log file that keeps track of session events', async function () {
17511803
expect(await shell.executeLine('print(123 + 456)')).to.include('579');
17521804
const log = await readLogFile();

0 commit comments

Comments
 (0)