7
7
"os"
8
8
"path/filepath"
9
9
"strings"
10
+ "sync"
10
11
"testing"
11
12
"time"
12
13
@@ -423,7 +424,7 @@ func measureDownloadTimePerf(t *testing.T, size int64, withVerification bool) ti
423
424
}
424
425
425
426
// BenchmarkS3Cache_ParallelDownloads measures concurrent download performance
426
- func BenchmarkS3Cache_ParallelDownloads_DISABLED (b * testing.B ) {
427
+ func BenchmarkS3Cache_ParallelDownloads (b * testing.B ) {
427
428
if testing .Short () {
428
429
b .Skip ("skipping benchmark in short mode" )
429
430
}
@@ -432,29 +433,56 @@ func BenchmarkS3Cache_ParallelDownloads_DISABLED(b *testing.B) {
432
433
433
434
for _ , concurrency := range concurrencyLevels {
434
435
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 ),
442
439
}
443
440
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
+ }
446
450
447
451
tmpDir := b .TempDir ()
448
452
449
453
b .ResetTimer ()
450
454
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
+ }
453
474
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
458
486
}
459
487
}
460
488
})
@@ -523,7 +551,7 @@ func TestS3Cache_ParallelVerificationScaling(t *testing.T) {
523
551
}
524
552
525
553
// BenchmarkS3Cache_ThroughputComparison compares baseline vs verified throughput
526
- func BenchmarkS3Cache_ThroughputComparison_DISABLED (b * testing.B ) {
554
+ func BenchmarkS3Cache_ThroughputComparison (b * testing.B ) {
527
555
if testing .Short () {
528
556
b .Skip ("skipping benchmark in short mode" )
529
557
}
0 commit comments