Skip to content

Commit 303d19b

Browse files
authored
Remove unncessary tests that are flaky (#6350)
1 parent 708216e commit 303d19b

File tree

3 files changed

+1
-217
lines changed

3 files changed

+1
-217
lines changed

services-custom/s3-transfer-manager/src/test/java/software/amazon/awssdk/transfer/s3/internal/AsyncBufferingSubscriberTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ void differentNumberOfStrings_shouldCompleteSuccessfully(int numberOfStrings) th
9898
assertThat(numRequestsInFlightSampling).contains(MAX_CONCURRENT_EXECUTIONS);
9999
}
100100
disposable.dispose();
101+
numRequestsInFlightSampling.forEach(maxConcurrency -> assertThat(maxConcurrency).isLessThanOrEqualTo(MAX_CONCURRENT_EXECUTIONS));
101102
}
102103

103104
@Test

services-custom/s3-transfer-manager/src/test/java/software/amazon/awssdk/transfer/s3/internal/DownloadDirectoryHelperTest.java

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -526,114 +526,6 @@ void downloadDirectory_withListObjectsRequestTransformer_transformerThrows_fails
526526

527527
assertThatThrownBy(downloadDirectory.completionFuture()::join).hasCause(exception);
528528
}
529-
@Test
530-
void downloadDirectory_customMaxConcurrency_shouldLimitConcurrentOperations() throws Exception {
531-
// Create many S3 objects to test concurrency
532-
int totalFiles = 50;
533-
String[] keys = new String[totalFiles];
534-
for (int i = 0; i < totalFiles; i++) {
535-
keys[i] = "file" + i + ".txt";
536-
}
537-
stubSuccessfulListObjects(listObjectsHelper, keys);
538-
539-
// Configuration with expected concurrency limit
540-
int configuredMaxConcurrency = 5;
541-
542-
// Track concurrent operations
543-
AtomicInteger currentlyActive = new AtomicInteger(0);
544-
AtomicInteger peakConcurrency = new AtomicInteger(0);
545-
546-
// Use a Phaser to coordinate phases
547-
Phaser phaser = new Phaser(1); // Start with test thread
548-
549-
// Mock the single download function to track concurrent operations
550-
when(singleDownloadFunction.apply(any())).thenAnswer(invocation -> {
551-
phaser.register(); // Each operation registers
552-
553-
CompletableFuture<CompletedFileDownload> future = new CompletableFuture<>();
554-
555-
CompletableFuture.runAsync(() -> {
556-
try {
557-
// Track entry
558-
int current = currentlyActive.incrementAndGet();
559-
peakConcurrency.updateAndGet(max -> Math.max(max, current));
560-
561-
// Wait at barrier - this forces all operations to be active simultaneously
562-
phaser.arriveAndAwaitAdvance();
563-
564-
// Complete
565-
future.complete(CompletedFileDownload.builder()
566-
.response(GetObjectResponse.builder().eTag("test").build())
567-
.build());
568-
569-
} catch (Exception e) {
570-
future.completeExceptionally(e);
571-
} finally {
572-
currentlyActive.decrementAndGet();
573-
phaser.arriveAndDeregister();
574-
}
575-
});
576-
577-
return new DefaultFileDownload(future,
578-
new DefaultTransferProgress(DefaultTransferProgressSnapshot.builder()
579-
.transferredBytes(0L)
580-
.build()),
581-
() -> DownloadFileRequest.builder()
582-
.getObjectRequest(GetObjectRequest.builder().build())
583-
.destination(Paths.get("."))
584-
.build(),
585-
null);
586-
});
587-
588-
// Configure with our expected limit
589-
// To verify test works as intended, verify test failure when transferDirectoryMaxConcurrency is
590-
// configuredMaxConcurrency + 1 or configuredMaxConcurrency - 1
591-
TransferManagerConfiguration customConfig = TransferManagerConfiguration.builder()
592-
.transferDirectoryMaxConcurrency(configuredMaxConcurrency)
593-
.build();
594-
595-
DownloadDirectoryHelper customHelper = new DownloadDirectoryHelper(
596-
customConfig, listObjectsHelper, singleDownloadFunction);
597-
598-
// Start download asynchronously
599-
CompletableFuture<Void> downloadTask = CompletableFuture.runAsync(() -> {
600-
DirectoryDownload download = customHelper.downloadDirectory(
601-
DownloadDirectoryRequest.builder()
602-
.destination(directory)
603-
.bucket("bucket")
604-
.build()
605-
);
606-
download.completionFuture().join();
607-
});
608-
609-
// Wait for operations to register (but not complete the phase)
610-
// We wait for more than the configured limit to ensure we'd catch violations
611-
Duration maxWait = Duration.ofSeconds(5);
612-
long deadline = System.nanoTime() + maxWait.toNanos();
613-
int current = phaser.getRegisteredParties() - 1; // Subtract 1 for main thread
614-
while (current < configuredMaxConcurrency) {
615-
if (System.nanoTime() >= deadline) {
616-
throw new AssertionError(
617-
"Timed out waiting for registrations: current=" + current +
618-
", configuredMaxConcurrency=" + configuredMaxConcurrency);
619-
}
620-
LockSupport.parkNanos(10_000_000L); // ~10 ms
621-
current = phaser.getRegisteredParties() - 1;
622-
}
623-
624-
// Check peak BEFORE releasing the phase
625-
int observedPeak = peakConcurrency.get();
626-
assertThat(observedPeak)
627-
.as("Implementation allowed %d concurrent operations but was configured for %d",
628-
observedPeak, configuredMaxConcurrency)
629-
.isEqualTo(configuredMaxConcurrency);
630-
631-
// Release the phase to let operations complete
632-
phaser.arriveAndDeregister();
633-
634-
// Complete the test
635-
downloadTask.get(2, TimeUnit.SECONDS);
636-
}
637529

638530
private static DefaultFileDownload completedDownload() {
639531
return new DefaultFileDownload(CompletableFuture.completedFuture(CompletedFileDownload.builder()

services-custom/s3-transfer-manager/src/test/java/software/amazon/awssdk/transfer/s3/internal/UploadDirectoryHelperTest.java

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -462,115 +462,6 @@ public void uploadDirectory_requestTransformFunctionThrows_failsUpload() {
462462
assertThatThrownBy(uploadFuture::join).getCause().hasCause(exception);
463463
}
464464

465-
@Test
466-
void uploadDirectory_customMaxConcurrency_shouldLimitConcurrentOperations() throws Exception {
467-
// Create many files to test concurrency
468-
Path testDir = jimfs.getPath("concurrencyTest");
469-
Files.createDirectory(testDir);
470-
int totalFiles = 50;
471-
for (int i = 0; i < totalFiles; i++) {
472-
Files.createFile(jimfs.getPath("concurrencyTest/file" + i + ".txt"));
473-
}
474-
475-
// Configuration with expected concurrency limit
476-
int configuredMaxConcurrency = 5;
477-
478-
// Track concurrent operations
479-
AtomicInteger currentlyActive = new AtomicInteger(0);
480-
AtomicInteger peakConcurrency = new AtomicInteger(0);
481-
482-
// Use a Phaser to coordinate phases
483-
Phaser phaser = new Phaser(1); // Start with test thread
484-
485-
// Mock the single upload function to track concurrent operations
486-
when(singleUploadFunction.apply(any())).thenAnswer(invocation -> {
487-
phaser.register(); // Each operation registers
488-
489-
CompletableFuture<CompletedFileUpload> future = new CompletableFuture<>();
490-
491-
CompletableFuture.runAsync(() -> {
492-
try {
493-
// Track entry
494-
int current = currentlyActive.incrementAndGet();
495-
peakConcurrency.updateAndGet(max -> Math.max(max, current));
496-
497-
// Wait at barrier - this forces all operations to be active simultaneously
498-
phaser.arriveAndAwaitAdvance();
499-
500-
// Complete
501-
future.complete(CompletedFileUpload.builder()
502-
.response(PutObjectResponse.builder().eTag("test").build())
503-
.build());
504-
505-
} catch (Exception e) {
506-
future.completeExceptionally(e);
507-
} finally {
508-
currentlyActive.decrementAndGet();
509-
phaser.arriveAndDeregister();
510-
}
511-
});
512-
513-
return new DefaultFileUpload(future,
514-
new DefaultTransferProgress(DefaultTransferProgressSnapshot.builder()
515-
.transferredBytes(0L)
516-
.build()),
517-
new PauseObservable(),
518-
UploadFileRequest.builder()
519-
.putObjectRequest(p -> p.key("key").bucket("bucket"))
520-
.source(Paths.get("test.txt"))
521-
.build());
522-
});
523-
524-
// Configure with our expected limit
525-
// To verify test works as intended, verify test failure when transferDirectoryMaxConcurrency is
526-
// configuredMaxConcurrency + 1 or configuredMaxConcurrency - 1
527-
TransferManagerConfiguration customConfig = TransferManagerConfiguration.builder()
528-
.transferDirectoryMaxConcurrency(configuredMaxConcurrency)
529-
.build();
530-
531-
UploadDirectoryHelper customHelper = new UploadDirectoryHelper(customConfig, singleUploadFunction);
532-
533-
// Start upload asynchronously
534-
CompletableFuture<Void> uploadTask = CompletableFuture.runAsync(() -> {
535-
DirectoryUpload upload = customHelper.uploadDirectory(
536-
UploadDirectoryRequest.builder()
537-
.source(testDir)
538-
.bucket("bucket")
539-
.build()
540-
);
541-
upload.completionFuture().join();
542-
});
543-
544-
// Wait for operations to register (but not complete the phase)
545-
// We wait for more than the configured limit to ensure we'd catch violations
546-
Duration maxWait = Duration.ofSeconds(5);
547-
long deadline = System.nanoTime() + maxWait.toNanos();
548-
int current = phaser.getRegisteredParties() - 1; // Subtract 1 for main thread
549-
while (current < configuredMaxConcurrency) {
550-
if (System.nanoTime() >= deadline) {
551-
throw new AssertionError(
552-
"Timed out waiting for registrations: current=" + current +
553-
", configuredMaxConcurrency=" + configuredMaxConcurrency);
554-
}
555-
LockSupport.parkNanos(10_000_000L); // ~10 ms
556-
current = phaser.getRegisteredParties() - 1;
557-
}
558-
559-
// Check peak BEFORE releasing the phase
560-
int observedPeak = peakConcurrency.get();
561-
assertThat(observedPeak)
562-
.as("Implementation allowed %d concurrent operations but was configured for %d",
563-
observedPeak, configuredMaxConcurrency)
564-
.isLessThanOrEqualTo(configuredMaxConcurrency);
565-
566-
// Release the phase to let operations complete
567-
phaser.arriveAndDeregister();
568-
569-
// Complete the test
570-
uploadTask.get(2, TimeUnit.SECONDS);
571-
}
572-
573-
574465
private DefaultFileUpload completedUpload() {
575466
return new DefaultFileUpload(CompletableFuture.completedFuture(CompletedFileUpload.builder()
576467
.response(PutObjectResponse.builder().build())

0 commit comments

Comments
 (0)