Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 0 additions & 152 deletions pkg/leeway/cache/remote/s3_performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,6 @@ func (m *realisticMockVerifier) VerifyArtifact(ctx context.Context, artifactPath
return nil // Success
}

// Test helper: Create realistic mock S3 storage for performance testing
func createRealisticMockS3Storage(t testing.TB, artifactPath string, attestation []byte) *realisticMockS3Storage {
data, err := os.ReadFile(artifactPath)
require.NoError(t, err)

storage := &realisticMockS3Storage{
objects: map[string][]byte{
"test-package:v1.tar.gz": data,
},
}

if attestation != nil {
storage.objects["test-package:v1.tar.gz.att"] = attestation
}

return storage
}

// Test helper: Create realistic mock S3 storage for multiple packages
func createRealisticMockS3StorageMultiple(t testing.TB, packageCount int) *realisticMockS3Storage {
storage := &realisticMockS3Storage{
Expand Down Expand Up @@ -289,140 +271,6 @@ func BenchmarkS3Cache_DownloadWithVerification(b *testing.B) {
}
}

// TestS3Cache_VerificationOverhead validates verification overhead
// Note: This test may show inconsistent results due to S3Cache optimizations
// For accurate performance measurements, use the benchmark functions instead
func TestS3Cache_VerificationOverhead(t *testing.T) {
if testing.Short() {
t.Skip("skipping performance test in short mode")
}

t.Log("Note: For accurate performance measurements, run benchmarks:")
t.Log("go test -bench=BenchmarkS3Cache_DownloadBaseline")
t.Log("go test -bench=BenchmarkS3Cache_DownloadWithVerification")

sizes := []struct {
name string
size int64
}{
{"1MB", 1 * 1024 * 1024},
{"10MB", 10 * 1024 * 1024},
{"50MB", 50 * 1024 * 1024},
}

const targetOverhead = 100.0 // Lenient target due to test limitations
const iterations = 3 // Average over multiple runs for better accuracy

for _, tt := range sizes {
t.Run(tt.name, func(t *testing.T) {
// Measure baseline (no verification)
var baselineTotal time.Duration
for i := 0; i < iterations; i++ {
duration := measureDownloadTimePerf(t, tt.size, false)
baselineTotal += duration
}
baselineAvg := baselineTotal / iterations

// Measure with SLSA verification
var verifiedTotal time.Duration
for i := 0; i < iterations; i++ {
duration := measureDownloadTimePerf(t, tt.size, true)
verifiedTotal += duration
}
verifiedAvg := verifiedTotal / iterations

// Calculate overhead percentage
overhead := float64(verifiedAvg-baselineAvg) / float64(baselineAvg) * 100

t.Logf("Size: %s, Baseline: %v, Verified: %v, Overhead: %.2f%%",
tt.name, baselineAvg, verifiedAvg, overhead)

// Assert overhead is within target
if overhead > targetOverhead {
t.Errorf("Verification overhead %.2f%% exceeds target of %.2f%%",
overhead, targetOverhead)
} else {
t.Logf("✓ Overhead %.2f%% is within target", overhead)
}
})
}
}

// measureDownloadTimePerf measures a single download operation for performance testing
func measureDownloadTimePerf(t *testing.T, size int64, withVerification bool) time.Duration {
// Create test artifact with unique name to avoid caching
artifactPath := createSizedArtifact(t, size)
defer os.Remove(artifactPath)

// Setup cache with unique package name to avoid caching
packageName := fmt.Sprintf("test-package-%d", time.Now().UnixNano())
config := &cache.RemoteConfig{
BucketName: "test-bucket",
}

if withVerification {
attestation := createMockAttestation(t)
config.SLSA = &cache.SLSAConfig{
Verification: true,
SourceURI: "github.com/gitpod-io/leeway",
RequireAttestation: false,
}

mockStorage := createRealisticMockS3Storage(t, artifactPath, attestation)
// Update storage with unique package name
data := mockStorage.objects["test-package:v1.tar.gz"]
delete(mockStorage.objects, "test-package:v1.tar.gz")
delete(mockStorage.objects, "test-package:v1.tar.gz.att")
mockStorage.objects[packageName+":v1.tar.gz"] = data
mockStorage.objects[packageName+":v1.tar.gz.att"] = attestation

mockVerifier := &realisticMockVerifier{}

s3Cache := &S3Cache{
storage: mockStorage,
cfg: config,
slsaVerifier: mockVerifier,
}

tmpDir := t.TempDir()
localCache, _ := local.NewFilesystemCache(tmpDir)
pkg := &mockPackagePerf{version: "v1", fullName: packageName}

// Ensure package doesn't exist locally to force download
packages := []cache.Package{pkg}

start := time.Now()
err := s3Cache.Download(context.Background(), localCache, packages)
require.NoError(t, err)

return time.Since(start)
} else {
mockStorage := createRealisticMockS3Storage(t, artifactPath, nil)
// Update storage with unique package name
data := mockStorage.objects["test-package:v1.tar.gz"]
delete(mockStorage.objects, "test-package:v1.tar.gz")
mockStorage.objects[packageName+":v1.tar.gz"] = data

s3Cache := &S3Cache{
storage: mockStorage,
cfg: config,
}

tmpDir := t.TempDir()
localCache, _ := local.NewFilesystemCache(tmpDir)
pkg := &mockPackagePerf{version: "v1", fullName: packageName}

// Ensure package doesn't exist locally to force download
packages := []cache.Package{pkg}

start := time.Now()
err := s3Cache.Download(context.Background(), localCache, packages)
require.NoError(t, err)

return time.Since(start)
}
}

// BenchmarkS3Cache_ParallelDownloads measures concurrent download performance
func BenchmarkS3Cache_ParallelDownloads(b *testing.B) {
if testing.Short() {
Expand Down
Loading