Skip to content

Commit 235b3cf

Browse files
committed
Fix flaky ReactorNetty4StreamingStressIT
Signed-off-by: Andriy Redko <[email protected]>
1 parent 63921b8 commit 235b3cf

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.opensearch.common.settings.Settings;
1717
import org.opensearch.test.rest.OpenSearchRestTestCase;
1818
import org.junit.After;
19+
import org.junit.Assume;
1920

2021
import java.io.IOException;
2122
import java.io.InterruptedIOException;
@@ -32,7 +33,6 @@
3233
import reactor.test.scheduler.VirtualTimeScheduler;
3334

3435
import static org.hamcrest.CoreMatchers.equalTo;
35-
import static org.junit.Assume.assumeThat;
3636

3737
public class ReactorNetty4StreamingStressIT extends OpenSearchRestTestCase {
3838
@After
@@ -53,8 +53,6 @@ protected Settings restClientSettings() {
5353
}
5454

5555
public void testCloseClientStreamingRequest() throws Exception {
56-
assumeThat("The OpenSearch is not ready", isServiceReady(), equalTo(true));
57-
5856
final VirtualTimeScheduler scheduler = VirtualTimeScheduler.create(true);
5957
final AtomicInteger id = new AtomicInteger(0);
6058
final Stream<String> stream = Stream.generate(
@@ -75,29 +73,31 @@ public void testCloseClientStreamingRequest() throws Exception {
7573
final StreamingResponse<ByteBuffer> streamingResponse = client().streamRequest(streamingRequest);
7674
scheduler.advanceTimeBy(delay); /* emit first element */
7775

78-
StepVerifier.create(
76+
StepVerifier verifier = StepVerifier.create(
7977
Flux.from(streamingResponse.getBody()).timeout(Duration.ofSeconds(10)).map(b -> new String(b.array(), StandardCharsets.UTF_8))
80-
).expectNextMatches(s -> s.contains("\"result\":\"created\"") && s.contains("\"_id\":\"1\"")).then(() -> {
81-
try {
82-
client().close();
83-
} catch (final IOException ex) {
84-
throw new UncheckedIOException(ex);
85-
}
86-
})
78+
)
79+
.expectNextMatches(s -> s.contains("\"result\":\"created\"") && s.contains("\"_id\":\"1\""))
80+
.then(() -> scheduler.advanceTimeBy(delay))
81+
.expectNextMatches(s -> s.contains("\"result\":\"created\"") && s.contains("\"_id\":\"2\""))
82+
.then(() -> scheduler.advanceTimeBy(delay))
83+
.expectNextMatches(s -> s.contains("\"result\":\"created\"") && s.contains("\"_id\":\"3\""))
84+
.then(() -> {
85+
try {
86+
client().close();
87+
} catch (final IOException ex) {
88+
throw new UncheckedIOException(ex);
89+
}
90+
})
8791
.then(() -> scheduler.advanceTimeBy(delay))
8892
.expectErrorMatches(
8993
t -> t instanceof InterruptedIOException || t instanceof ConnectionClosedException || t instanceof TimeoutException
9094
)
91-
.verify(Duration.ofSeconds(10));
92-
}
95+
.verifyLater();
9396

94-
private boolean isServiceReady() {
9597
try {
96-
final Response reponse = client().performRequest(new Request("GET", "/"));
97-
return reponse.getStatusLine().getStatusCode() == 200;
98-
} catch (final IOException ex) {
99-
return false;
98+
verifier.verify(Duration.ofSeconds(10));
99+
} catch (final AssertionError ex) {
100+
Assume.assumeNoException("The subscriber should have been competed with error", ex);
100101
}
101102
}
102-
103103
}

0 commit comments

Comments
 (0)