@@ -700,6 +700,45 @@ func TestBackfill(t *testing.T) {
700700 }
701701}
702702
703+ func TestCopyFileDoesNotMutateResourceNameCompressor (t * testing.T ) {
704+ env , _ , ctx := getEnvAuthAndCtx (t )
705+ singleCacheSizeBytes := int64 (1000000 )
706+ peer1 := fmt .Sprintf ("localhost:%d" , testport .FindFree (t ))
707+ peer2 := fmt .Sprintf ("localhost:%d" , testport .FindFree (t ))
708+ baseConfig := Options {
709+ ReplicationFactor : 2 ,
710+ Nodes : []string {peer1 , peer2 },
711+ DisableLocalLookup : true ,
712+ EnableLocalCompressionLookup : true ,
713+ }
714+
715+ sourceCache := & testcompression.CompressionCache {Cache : newMemoryCache (t , singleCacheSizeBytes )}
716+ config1 := baseConfig
717+ config1 .ListenAddr = peer1
718+ dc1 := startNewDCache (t , env , config1 , sourceCache )
719+
720+ destCache := & testcompression.CompressionCache {Cache : newMemoryCache (t , singleCacheSizeBytes )}
721+ config2 := baseConfig
722+ config2 .ListenAddr = peer2
723+ _ = startNewDCache (t , env , config2 , destCache )
724+
725+ waitForReady (t , config1 .ListenAddr )
726+ waitForReady (t , config2 .ListenAddr )
727+
728+ // Note: the value `200` here is intentionally greater than
729+ // cache.pebble.min_bytes_auto_zstd_compression
730+ rn , buf := testdigest .RandomCASResourceBuf (t , 200 )
731+ require .Equal (t , repb .Compressor_IDENTITY , rn .GetCompressor ())
732+ require .NoError (t , sourceCache .Set (ctx , rn , buf ))
733+
734+ require .NoError (t , dc1 .copyFile (ctx , rn , peer1 , peer2 ))
735+ require .Equal (t , repb .Compressor_IDENTITY , rn .GetCompressor (), "copyFile should not mutate the caller's resource name" )
736+
737+ got , err := destCache .Get (ctx , rn )
738+ require .NoError (t , err )
739+ require .Equal (t , buf , got )
740+ }
741+
703742func TestContainsMulti (t * testing.T ) {
704743 env , _ , ctx := getEnvAuthAndCtx (t )
705744 singleCacheSizeBytes := int64 (1000000 )
0 commit comments