Skip to content

Commit 14152de

Browse files
leodidoona-agent
andcommitted
Fix test initialization to prevent SIGSEGV crashes
- Initialize rateLimiter and semaphore in all test S3Cache instances - Add required imports for golang.org/x/time/rate - Fix nil pointer dereferences that caused segmentation violations - Ensure all tests properly initialize production-ready S3Cache fields - Maintain test compatibility with new concurrency safety features Fixes critical issue where tests created S3Cache directly without going through constructor, leaving essential fields uninitialized. Co-authored-by: Ona <[email protected]>
1 parent de2c2fe commit 14152de

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pkg/leeway/cache/remote/s3_download_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/gitpod-io/leeway/pkg/leeway/cache"
1313
"github.com/gitpod-io/leeway/pkg/leeway/cache/local"
1414
"github.com/google/go-cmp/cmp"
15+
"golang.org/x/time/rate"
1516
)
1617

1718
// s3TestPackage for testing S3 download functionality
@@ -175,6 +176,8 @@ func TestS3CacheDownload(t *testing.T) {
175176
s3Cache := &S3Cache{
176177
storage: mockStorage,
177178
workerCount: 1,
179+
rateLimiter: rate.NewLimiter(rate.Limit(defaultRateLimit), defaultBurstLimit),
180+
semaphore: make(chan struct{}, maxConcurrentOperations),
178181
}
179182

180183
err := s3Cache.Download(context.Background(), localCache, tt.packages)

pkg/leeway/cache/remote/s3_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/aws/smithy-go"
1919
"github.com/gitpod-io/leeway/pkg/leeway/cache"
2020
"github.com/google/go-cmp/cmp"
21+
"golang.org/x/time/rate"
2122
)
2223

2324
// mockS3Client implements a mock S3 client for testing
@@ -149,6 +150,8 @@ func TestS3Cache_ExistingPackages(t *testing.T) {
149150
bucketName: "test-bucket",
150151
},
151152
workerCount: 1,
153+
rateLimiter: rate.NewLimiter(rate.Limit(defaultRateLimit), defaultBurstLimit),
154+
semaphore: make(chan struct{}, maxConcurrentOperations),
152155
}
153156

154157
results, err := s3Cache.ExistingPackages(ctx, tt.packages)
@@ -291,6 +294,8 @@ func TestS3Cache_Download(t *testing.T) {
291294
bucketName: "test-bucket",
292295
},
293296
workerCount: 1,
297+
rateLimiter: rate.NewLimiter(rate.Limit(defaultRateLimit), defaultBurstLimit),
298+
semaphore: make(chan struct{}, maxConcurrentOperations),
294299
}
295300

296301
err := s3Cache.Download(ctx, tt.localCache, tt.packages)
@@ -420,6 +425,8 @@ func TestS3Cache_Upload(t *testing.T) {
420425
bucketName: "test-bucket",
421426
},
422427
workerCount: 1,
428+
rateLimiter: rate.NewLimiter(rate.Limit(defaultRateLimit), defaultBurstLimit),
429+
semaphore: make(chan struct{}, maxConcurrentOperations),
423430
}
424431

425432
err := s3Cache.Upload(ctx, tt.localCache, tt.packages)

0 commit comments

Comments
 (0)