@@ -1268,15 +1268,46 @@ func TestFileCacheWriteCleansUpTempFile(t *testing.T) {
12681268 rn , buf := testdigest .RandomCASResourceBuf (t , 1024 )
12691269 node := & repb.FileNode {Digest : rn .GetDigest ()}
12701270
1271- _ , err = fc .Write (ctx , node , buf )
1271+ // Write the bytes through the convenience API and expect it to report the
1272+ // full accepted byte count.
1273+ n , err := fc .Write (ctx , node , buf )
12721274 require .NoError (t , err )
1275+ require .Equal (t , len (buf ), n )
12731276
1277+ // The temporary staging file should be removed after the file is added to
1278+ // the cache.
12741279 pattern := filepath .Join (fc .TempDir (), rn .GetDigest ().GetHash ()+ ".*.tmp" )
12751280 matches , err := filepath .Glob (pattern )
12761281 require .NoError (t , err )
12771282 require .Empty (t , matches , "expected temp file(s) to be deleted: %v" , matches )
12781283}
12791284
1285+ func TestFileCacheWriteAfterClose (t * testing.T ) {
1286+ flags .Set (t , "executor.delete_filecache_on_unclean_shutdown" , true )
1287+ ctx := context .Background ()
1288+ fcDir := testfs .MakeTempDir (t )
1289+ outputDir := testfs .MakeTempDir (t )
1290+ fc , err := filecache .NewFileCache (fcDir , 100000 , false )
1291+ require .NoError (t , err )
1292+ fc .WaitForDirectoryScanToComplete ()
1293+
1294+ rn , buf := testdigest .RandomCASResourceBuf (t , 1024 )
1295+ node := & repb.FileNode {Digest : rn .GetDigest ()}
1296+
1297+ // Once the cache is closing, Write should silently accept the bytes so
1298+ // callers do not fail just because cache population is best-effort.
1299+ require .NoError (t , fc .Close ())
1300+ n , err := fc .Write (ctx , node , buf )
1301+ require .NoError (t , err )
1302+ require .Equal (t , len (buf ), n )
1303+
1304+ // The accepted bytes are intentionally dropped rather than added to the
1305+ // cache after shutdown starts.
1306+ linkedPath := filepath .Join (outputDir , "linked-after-close" )
1307+ require .False (t , fc .FastLinkFile (ctx , node , linkedPath ))
1308+ require .NoFileExists (t , linkedPath )
1309+ }
1310+
12801311func TestTrackExternalDirectory_Basic (t * testing.T ) {
12811312 ctx := context .Background ()
12821313 fcDir := testfs .MakeTempDir (t )
0 commit comments