77 "os"
88 "path/filepath"
99 "strings"
10+ "sync"
1011 "testing"
1112 "time"
1213
@@ -423,7 +424,7 @@ func measureDownloadTimePerf(t *testing.T, size int64, withVerification bool) ti
423424}
424425
425426// BenchmarkS3Cache_ParallelDownloads measures concurrent download performance
426- func BenchmarkS3Cache_ParallelDownloads_DISABLED (b * testing.B ) {
427+ func BenchmarkS3Cache_ParallelDownloads (b * testing.B ) {
427428 if testing .Short () {
428429 b .Skip ("skipping benchmark in short mode" )
429430 }
@@ -432,29 +433,56 @@ func BenchmarkS3Cache_ParallelDownloads_DISABLED(b *testing.B) {
432433
433434 for _ , concurrency := range concurrencyLevels {
434435 b .Run (fmt .Sprintf ("%d-concurrent" , concurrency ), func (b * testing.B ) {
435- // Setup multiple packages
436- packages := make ([]cache.Package , concurrency )
437- for i := 0 ; i < concurrency ; i ++ {
438- packages [i ] = & mockPackagePerf {
439- version : fmt .Sprintf ("v%d" , i ),
440- fullName : fmt .Sprintf ("package%d" , i ),
441- }
436+ // Create mock storage with multiple unique packages
437+ mockStorage := & realisticMockS3Storage {
438+ objects : make (map [string ][]byte ),
442439 }
443440
444- // Setup mock storage with multiple artifacts
445- mockStorage := createRealisticMockS3StorageMultiple (b , concurrency )
441+ // Create small artifacts for each package
442+ artifactData := make ([]byte , 1024 * 1024 ) // 1MB each
443+ _ , err := rand .Read (artifactData )
444+ require .NoError (b , err )
445+
446+ for i := 0 ; i < concurrency ; i ++ {
447+ key := fmt .Sprintf ("package%d:v1.tar.gz" , i )
448+ mockStorage .objects [key ] = artifactData
449+ }
446450
447451 tmpDir := b .TempDir ()
448452
449453 b .ResetTimer ()
450454 for i := 0 ; i < b .N ; i ++ {
451- // Directly test the realistic mock to ensure it's being used
452- dest := filepath .Join (tmpDir , fmt .Sprintf ("artifact-%d.tar.gz" , i ))
455+ // Download all packages concurrently
456+ var wg sync.WaitGroup
457+ errChan := make (chan error , concurrency )
458+
459+ for j := 0 ; j < concurrency ; j ++ {
460+ wg .Add (1 )
461+ go func (idx int ) {
462+ defer wg .Done ()
463+
464+ key := fmt .Sprintf ("package%d:v1.tar.gz" , idx )
465+ dest := filepath .Join (tmpDir , fmt .Sprintf ("artifact-%d-%d.tar.gz" , i , idx ))
466+
467+ _ , err := mockStorage .GetObject (context .Background (), key , dest )
468+ if err != nil {
469+ errChan <- err
470+ return
471+ }
472+ }(j )
473+ }
453474
454- // Download artifact only (no verification for baseline)
455- _ , err := mockStorage .GetObject (context .Background (), "test-package:v1.tar.gz" , dest )
456- if err != nil {
457- b .Fatal (err )
475+ wg .Wait ()
476+ close (errChan )
477+
478+ // Check for any errors
479+ select {
480+ case err := <- errChan :
481+ if err != nil {
482+ b .Fatal (err )
483+ }
484+ default :
485+ // No errors
458486 }
459487 }
460488 })
@@ -523,7 +551,7 @@ func TestS3Cache_ParallelVerificationScaling(t *testing.T) {
523551}
524552
525553// BenchmarkS3Cache_ThroughputComparison compares baseline vs verified throughput
526- func BenchmarkS3Cache_ThroughputComparison_DISABLED (b * testing.B ) {
554+ func BenchmarkS3Cache_ThroughputComparison (b * testing.B ) {
527555 if testing .Short () {
528556 b .Skip ("skipping benchmark in short mode" )
529557 }
0 commit comments