Skip to content

Commit a60cecd

Browse files
authored
Fix flaky Netty4Http3IT test suite (second attempt) (#20900)
Signed-off-by: Andriy Redko <drreta@gmail.com>
1 parent 5fb2c0a commit a60cecd

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

modules/transport-netty4/src/internalClusterTest/java/org/opensearch/http/netty4/Netty4Http3IT.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,18 @@ protected boolean addMockHttpTransport() {
7676
public void testThatNettyHttpServerSupportsHttp2OrHttp3Get() throws Exception {
7777
assumeThat("HTTP/3 is not available on this arch/platform", Http3Utils.isHttp3Available(), is(true));
7878

79+
ensureGreen();
80+
ensureFullyConnectedCluster();
81+
7982
String[] requests = new String[] { "/", "/_nodes/stats", "/", "/_cluster/state", "/" };
8083
HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class);
8184
TransportAddress[] boundAddresses = httpServerTransport.boundAddress().boundAddresses();
8285
TransportAddress transportAddress = randomFrom(boundAddresses);
8386

8487
@SuppressWarnings("unchecked")
8588
final Tuple<Netty4HttpClient, String> client = randomFrom(
86-
Tuple.tuple(Netty4HttpClient.http3(), "h2="),
87-
Tuple.tuple(Netty4HttpClient.https(), "h3=")
89+
Tuple.tuple(Netty4HttpClient.http3().withLogger(logger), "h2="),
90+
Tuple.tuple(Netty4HttpClient.https().withLogger(logger), "h3=")
8891
);
8992

9093
try (Netty4HttpClient nettyHttpClient = client.v1()) {
@@ -107,15 +110,18 @@ public void testThatNettyHttpServerSupportsHttp2OrHttp3Get() throws Exception {
107110
public void testThatNettyHttpServerSupportsHttp2OrHttp3Post() throws Exception {
108111
assumeThat("HTTP/3 is not available on this arch/platform", Http3Utils.isHttp3Available(), is(true));
109112

113+
ensureGreen();
114+
ensureFullyConnectedCluster();
115+
110116
final List<Tuple<String, CharSequence>> requests = List.of(Tuple.tuple("/_search", "{\"query\":{ \"match_all\":{}}}"));
111117
HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class);
112118
TransportAddress[] boundAddresses = httpServerTransport.boundAddress().boundAddresses();
113119
TransportAddress transportAddress = randomFrom(boundAddresses);
114120

115121
@SuppressWarnings("unchecked")
116122
final Tuple<Netty4HttpClient, String> client = randomFrom(
117-
Tuple.tuple(Netty4HttpClient.http3(), "h2="),
118-
Tuple.tuple(Netty4HttpClient.https(), "h3=")
123+
Tuple.tuple(Netty4HttpClient.http3().withLogger(logger), "h2="),
124+
Tuple.tuple(Netty4HttpClient.https().withLogger(logger), "h3=")
119125
);
120126

121127
try (Netty4HttpClient nettyHttpClient = client.v1()) {

modules/transport-netty4/src/main/java/org/opensearch/http/netty4/Netty4Http3ServerTransport.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ protected void doStart() {
231231
@Override
232232
protected HttpServerChannel bind(InetSocketAddress socketAddress) throws Exception {
233233
ChannelFuture future = bootstrap.bind(socketAddress).sync();
234+
logger.info("Bound to {}", socketAddress);
235+
234236
Channel channel = future.channel();
235237
Netty4HttpServerChannel httpServerChannel = new Netty4HttpServerChannel(channel);
236238
channel.attr(HTTP_SERVER_CHANNEL_KEY).set(httpServerChannel);

modules/transport-netty4/src/test/java/org/opensearch/http/netty4/Netty4HttpClient.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
package org.opensearch.http.netty4;
3434

35+
import org.apache.logging.log4j.Level;
36+
import org.apache.logging.log4j.Logger;
3537
import org.opensearch.common.TriFunction;
3638
import org.opensearch.common.collect.Tuple;
3739
import org.opensearch.common.settings.Settings;
@@ -117,7 +119,6 @@
117119
* Tiny helper to send http requests over netty.
118120
*/
119121
public class Netty4HttpClient implements Closeable {
120-
121122
static Collection<String> returnHttpResponseBodies(Collection<FullHttpResponse> responses) {
122123
List<String> list = new ArrayList<>(responses.size());
123124
for (FullHttpResponse response : responses) {
@@ -137,6 +138,7 @@ static Collection<String> returnOpaqueIds(Collection<FullHttpResponse> responses
137138
private final Bootstrap clientBootstrap;
138139
private final TriFunction<CountDownLatch, Collection<FullHttpResponse>, Boolean, AwaitableChannelInitializer<?>> handlerFactory;
139140
private final boolean secure;
141+
private Logger logger;
140142

141143
Netty4HttpClient(
142144
Bootstrap clientBootstrap,
@@ -188,6 +190,11 @@ public static Netty4HttpClient http3() {
188190
);
189191
}
190192

193+
public Netty4HttpClient withLogger(Logger logger) {
194+
this.logger = logger;
195+
return this;
196+
}
197+
191198
public List<FullHttpResponse> get(SocketAddress remoteAddress, String... uris) throws InterruptedException {
192199
List<HttpRequest> requests = new ArrayList<>(uris.length);
193200
for (int i = 0; i < uris.length; i++) {
@@ -244,6 +251,7 @@ private synchronized List<FullHttpResponse> sendRequests(final SocketAddress rem
244251
final List<FullHttpResponse> content = Collections.synchronizedList(new ArrayList<>(requests.size()));
245252

246253
final AwaitableChannelInitializer<?> handler = handlerFactory.apply(latch, content, secure);
254+
handler.logger = logger;
247255
clientBootstrap.handler(handler);
248256

249257
ChannelFuture channelFuture = null;
@@ -341,6 +349,14 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
341349
*
342350
*/
343351
private static abstract class AwaitableChannelInitializer<C extends Channel> extends ChannelInitializer<C> {
352+
private Logger logger;
353+
354+
void log(Level level, String message, Object... params) {
355+
if (logger != null) {
356+
logger.log(level, message, params);
357+
}
358+
}
359+
344360
void await() {
345361
// do nothing
346362
}
@@ -518,6 +534,8 @@ protected void initChannel(DatagramChannel ch) {
518534

519535
@Override
520536
Channel prepare(Bootstrap clientBootstrap, Channel channel) throws InterruptedException {
537+
log(Level.INFO, "[QuicChannel] Connecting to: {}", channel.remoteAddress());
538+
521539
final QuicChannel quicChannel = QuicChannel.newBootstrap(channel)
522540
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30000) // 30 seconds
523541
.handler(new Http3ClientConnectionHandler())

0 commit comments

Comments
 (0)