Skip to content

Commit 700f7b9

Browse files
authored
Fix flaky tests in crt http client (#5022)
1 parent 09a12bf commit 700f7b9

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/internal/BaseHttpStreamResponseHandlerTest.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ void publisherWritesFutureCompletesAfterConnectionClosed_shouldNotInvokeIncremen
183183
}
184184

185185
@Test
186-
void publisherWritesFutureCompletesWhenConnectionClosed_shouldNotInvokeIncrementWindow() {
186+
void publisherWritesFutureCompletesBeforeConnectionClosed_shouldInvokeIncrementWindow() {
187187
CompletableFuture<Void> future = new CompletableFuture<>();
188188
when(simplePublisher.send(any(ByteBuffer.class))).thenReturn(future);
189189
when(simplePublisher.complete()).thenReturn(future);
@@ -199,23 +199,10 @@ void publisherWritesFutureCompletesWhenConnectionClosed_shouldNotInvokeIncrement
199199
handler.onResponseBody(httpStream,
200200
RandomStringUtils.random(1 * 1024 * 1024).getBytes(StandardCharsets.UTF_8));
201201

202-
// This tracker tracks which of the two operation completes first
203-
AtomicInteger whenCompleteTracker = new AtomicInteger(0);
204-
CompletableFuture<Void> onResponseComplete = CompletableFuture.runAsync(() -> handler.onResponseComplete(httpStream, 0))
205-
.whenComplete((r, t) -> whenCompleteTracker.compareAndSet(0, 1));
206-
207-
CompletableFuture<Void> writeComplete = CompletableFuture.runAsync(() -> future.complete(null))
208-
.whenComplete((r, t) -> whenCompleteTracker.compareAndSet(0, 2));
202+
future.complete(null);
203+
handler.onResponseComplete(httpStream, 0);
209204
requestFuture.join();
210-
211-
CompletableFuture.allOf(onResponseComplete, writeComplete).join();
212-
213-
if (whenCompleteTracker.get() == 1) {
214-
// onResponseComplete finishes first
215-
verify(httpStream, never()).incrementWindow(anyInt());
216-
} else {
217-
verify(httpStream).incrementWindow(anyInt());
218-
}
205+
verify(httpStream).incrementWindow(anyInt());
219206

220207
verify(crtConn, never()).shutdown();
221208
verify(crtConn).close();

0 commit comments

Comments
 (0)