@@ -1723,11 +1723,36 @@ describe('e2e', function () {
17231723 ) ;
17241724
17251725 expect ( await existingFiles ( paths ) ) . equals ( '1111111111' ) ;
1726+ } ) ;
1727+ } ) ;
1728+
1729+ describe ( 'with custom log max file count' , function ( ) {
1730+ const customLogDir = useTmpdir ( ) ;
1731+
1732+ it ( 'should delete files once it is above the max file limit' , async function ( ) {
1733+ const globalConfig = path . join ( homedir , 'globalconfig.conf' ) ;
1734+ await fs . writeFile (
1735+ globalConfig ,
1736+ `mongosh:\n logLocation: "${ customLogDir . path } "\n logMaxFileCount: 5`
1737+ ) ;
1738+ const paths : string [ ] = [ ] ;
1739+ const offset = Math . floor ( Date . now ( ) / 1000 ) ;
1740+ for ( let i = 0 ; i < 10 ; i ++ ) {
1741+ const filename = path . join (
1742+ customLogDir . path ,
1743+ ObjectId . createFromTime ( offset - i ) . toHexString ( ) + '_log'
1744+ ) ;
1745+ await fs . writeFile ( filename , '' ) ;
1746+ paths . unshift ( filename ) ;
1747+ }
17261748
1749+ // All 10 existing log files exist.
1750+ expect ( await existingFiles ( paths ) ) . to . equal ( '1111111111' ) ;
17271751 shell = this . startTestShell ( {
17281752 args : [ '--nodb' ] ,
17291753 env : {
17301754 ...env ,
1755+ MONGOSH_TEST_ONLY_MAX_LOG_FILE_COUNT : '' ,
17311756 MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING : globalConfig ,
17321757 } ,
17331758 forceTerminal : true ,
@@ -1736,9 +1761,24 @@ describe('e2e', function () {
17361761 await shell . waitForPrompt ( ) ;
17371762
17381763 // Add the newly created log file
1739- paths . push ( path . join ( customLogDir . path , `${ shell . logId } _log` ) ) ;
1764+ paths . push (
1765+ path . join ( customLogDir . path , `${ shell . logId as string } _log` )
1766+ ) ;
17401767 // Expect 6 files to be deleted and 5 to remain (including the new log file)
17411768 expect ( await existingFiles ( paths ) ) . equals ( '00000011111' ) ;
1769+ await shell . waitForPrompt ( ) ;
1770+
1771+ // Add the newly created log to the file list.
1772+ paths . push (
1773+ path . join ( customLogDir . path , `${ shell . logId as string } _log` )
1774+ ) ;
1775+
1776+ expect (
1777+ await shell . executeLine ( 'config.get("logMaxFileCount")' )
1778+ ) . contains ( '5' ) ;
1779+
1780+ // 6 of the oldest log files were deleted and 1 created.
1781+ expect ( await existingFiles ( paths ) ) . to . equal ( '00000011111' ) ;
17421782 } ) ;
17431783 } ) ;
17441784
0 commit comments