Skip to content

Commit b06ccd2

Browse files
authored
Fixing Flaky ReactorNetty4StreamingStressIT test case (another attempt) (#18193)
Signed-off-by: Andriy Redko <drreta@gmail.com>
1 parent d6e4db1 commit b06ccd2

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

plugins/transport-reactor-netty4/src/javaRestTest/java/org/opensearch/rest/ReactorNetty4StreamingStressIT.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.opensearch.client.Response;
1414
import org.opensearch.client.StreamingRequest;
1515
import org.opensearch.client.StreamingResponse;
16+
import org.opensearch.common.settings.Settings;
1617
import org.opensearch.test.rest.OpenSearchRestTestCase;
1718
import org.junit.After;
1819

@@ -22,6 +23,7 @@
2223
import java.nio.ByteBuffer;
2324
import java.nio.charset.StandardCharsets;
2425
import java.time.Duration;
26+
import java.util.concurrent.TimeoutException;
2527
import java.util.concurrent.atomic.AtomicInteger;
2628
import java.util.stream.Stream;
2729

@@ -44,7 +46,11 @@ public void tearDown() throws Exception {
4446
super.tearDown();
4547
}
4648

47-
@AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/15840")
49+
@Override
50+
protected Settings restClientSettings() {
51+
return Settings.builder().put(super.restClientSettings()).put(CLIENT_SOCKET_TIMEOUT, "5s").build();
52+
}
53+
4854
public void testCloseClientStreamingRequest() throws Exception {
4955
final VirtualTimeScheduler scheduler = VirtualTimeScheduler.create(true);
5056

@@ -67,17 +73,19 @@ public void testCloseClientStreamingRequest() throws Exception {
6773
final StreamingResponse<ByteBuffer> streamingResponse = client().streamRequest(streamingRequest);
6874
scheduler.advanceTimeBy(delay); /* emit first element */
6975

70-
StepVerifier.create(Flux.from(streamingResponse.getBody()).map(b -> new String(b.array(), StandardCharsets.UTF_8)))
71-
.expectNextMatches(s -> s.contains("\"result\":\"created\"") && s.contains("\"_id\":\"1\""))
72-
.then(() -> {
73-
try {
74-
client().close();
75-
} catch (final IOException ex) {
76-
throw new UncheckedIOException(ex);
77-
}
78-
})
76+
StepVerifier.create(
77+
Flux.from(streamingResponse.getBody()).timeout(Duration.ofSeconds(5)).map(b -> new String(b.array(), StandardCharsets.UTF_8))
78+
).expectNextMatches(s -> s.contains("\"result\":\"created\"") && s.contains("\"_id\":\"1\"")).then(() -> {
79+
try {
80+
client().close();
81+
} catch (final IOException ex) {
82+
throw new UncheckedIOException(ex);
83+
}
84+
})
7985
.then(() -> scheduler.advanceTimeBy(delay))
80-
.expectErrorMatches(t -> t instanceof InterruptedIOException || t instanceof ConnectionClosedException)
86+
.expectErrorMatches(
87+
t -> t instanceof InterruptedIOException || t instanceof ConnectionClosedException || t instanceof TimeoutException
88+
)
8189
.verify(Duration.ofSeconds(10));
8290
}
8391
}

0 commit comments

Comments
 (0)