@@ -13538,6 +13538,44 @@ func TestFileStoreSyncBlocksNoErrorOnConcurrentRemovedBlock(t *testing.T) {
1353813538 require_True (t , fs .werr == nil )
1353913539}
1354013540
13541+ func TestFileStoreDontExpireCacheWithRecentWrite (t * testing.T ) {
13542+ fcfg := FileStoreConfig {StoreDir : t .TempDir ()}
13543+ cfg := StreamConfig {Name : "zzz" , Storage : FileStorage , Subjects : []string {">" }}
13544+ fs , err := newFileStore (fcfg , cfg )
13545+ require_NoError (t , err )
13546+ defer fs .Stop ()
13547+
13548+ _ , _ , err = fs .StoreMsg ("foo" , nil , nil , 0 )
13549+ require_NoError (t , err )
13550+
13551+ // Cache should still exist after above write.
13552+ fmb := fs .getFirstBlock ()
13553+ fmb .mu .Lock ()
13554+ cacheLoaded := fmb .cacheAlreadyLoaded ()
13555+ fmb .llseq = 0
13556+ fmb .mu .Unlock ()
13557+ require_True (t , cacheLoaded )
13558+
13559+ // The load will try to expire the cache, but shouldn't due to the recent write.
13560+ _ , _ , err = fs .LoadNextMsg (fwcs , true , 0 , nil )
13561+ require_NoError (t , err )
13562+
13563+ fmb .mu .Lock ()
13564+ fmb .llseq = 0
13565+ cacheLoaded = fmb .cacheAlreadyLoaded ()
13566+ // We update the last write timestamp to be very old, so the next load can expire the cache.
13567+ fmb .lwts = 0
13568+ fmb .mu .Unlock ()
13569+ require_True (t , cacheLoaded )
13570+ _ , _ , err = fs .LoadNextMsg (fwcs , true , 0 , nil )
13571+ require_NoError (t , err )
13572+
13573+ fmb .mu .Lock ()
13574+ cacheLoaded = fmb .cacheAlreadyLoaded ()
13575+ fmb .mu .Unlock ()
13576+ require_False (t , cacheLoaded )
13577+ }
13578+
1354113579func TestFileStoreNoDirectoryNotEmptyError (t * testing.T ) {
1354213580 fcfg := FileStoreConfig {StoreDir : t .TempDir ()}
1354313581 mconfig := StreamConfig {Name : "TEST_DELETE" , Storage : FileStorage , Subjects : []string {"foo" }, Replicas : 1 }
0 commit comments