From c030a2dc0aeaa8c2ea4895fdfd51855f55401dbe Mon Sep 17 00:00:00 2001 From: Idel Pivnitskiy Date: Thu, 7 Nov 2024 13:57:53 -0800 Subject: [PATCH 1/2] Minor corrections for tests Modifications: - Reuse `CI` constant. - Use `localAddress` utility instead of `forPort` to avoid binding to non-locahost address that can be unavailable in some CI envs. --- .../http/netty/AbstractNettyHttpServerTest.java | 4 ++-- .../http/netty/ConnectionFactoryOffloadingTest.java | 3 ++- .../http/TrafficResilienceHttpServiceFilterTest.java | 11 ++++------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/AbstractNettyHttpServerTest.java b/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/AbstractNettyHttpServerTest.java index b7ef548bd7..91aca97d51 100644 --- a/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/AbstractNettyHttpServerTest.java +++ b/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/AbstractNettyHttpServerTest.java @@ -23,6 +23,7 @@ import io.servicetalk.concurrent.api.Executors; import io.servicetalk.concurrent.api.Publisher; import io.servicetalk.concurrent.api.Single; +import io.servicetalk.concurrent.internal.TestTimeoutConstants; import io.servicetalk.http.api.FilterableStreamingHttpConnection; import io.servicetalk.http.api.HttpLifecycleObserver; import io.servicetalk.http.api.HttpProtocolConfig; @@ -83,7 +84,6 @@ import static io.servicetalk.transport.netty.internal.AddressUtils.localAddress; import static io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort; import static io.servicetalk.utils.internal.ThrowableUtils.throwException; -import static java.lang.Boolean.parseBoolean; import static java.lang.Thread.NORM_PRIORITY; import static java.nio.charset.StandardCharsets.US_ASCII; import static java.util.Objects.requireNonNull; @@ -235,7 +235,7 @@ Single listen(HttpServerBuilder builder) { } void ignoreTestWhen(ExecutorSupplier clientExecutorSupplier, ExecutorSupplier serverExecutorSupplier) { - assumeFalse(parseBoolean(System.getenv("CI")) && + assumeFalse(TestTimeoutConstants.CI && this.clientExecutorSupplier == clientExecutorSupplier && this.serverExecutorSupplier == serverExecutorSupplier, "Ignored flaky test"); diff --git a/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/ConnectionFactoryOffloadingTest.java b/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/ConnectionFactoryOffloadingTest.java index 42aebd5c9f..618fe0f3a5 100644 --- a/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/ConnectionFactoryOffloadingTest.java +++ b/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/ConnectionFactoryOffloadingTest.java @@ -48,6 +48,7 @@ import static io.servicetalk.concurrent.api.AsyncCloseables.emptyAsyncCloseable; import static io.servicetalk.concurrent.api.Single.succeeded; import static io.servicetalk.http.api.HttpSerializers.textSerializerUtf8; +import static io.servicetalk.transport.netty.internal.AddressUtils.localAddress; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -71,7 +72,7 @@ void testFactoryOffloading(boolean offload, HttpExecutionStrategy httpStrategy) Thread appThread = Thread.currentThread(); - try (ServerContext server = HttpServers.forPort(0) + try (ServerContext server = HttpServers.forAddress(localAddress(0)) .listenAndAwait(ConnectionFactoryOffloadingTest::helloWorld)) { SocketAddress serverAddress = server.listenAddress(); diff --git a/servicetalk-traffic-resilience-http/src/test/java/io/servicetalk/traffic/resilience/http/TrafficResilienceHttpServiceFilterTest.java b/servicetalk-traffic-resilience-http/src/test/java/io/servicetalk/traffic/resilience/http/TrafficResilienceHttpServiceFilterTest.java index 14865db306..6efe0acc96 100644 --- a/servicetalk-traffic-resilience-http/src/test/java/io/servicetalk/traffic/resilience/http/TrafficResilienceHttpServiceFilterTest.java +++ b/servicetalk-traffic-resilience-http/src/test/java/io/servicetalk/traffic/resilience/http/TrafficResilienceHttpServiceFilterTest.java @@ -57,16 +57,15 @@ import static io.servicetalk.concurrent.api.Single.succeeded; import static io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION; import static io.servicetalk.http.api.HttpProtocolVersion.HTTP_1_1; +import static io.servicetalk.concurrent.internal.TestTimeoutConstants.CI; import static io.servicetalk.http.netty.AsyncContextHttpFilterVerifier.verifyServerFilterAsyncContextVisibility; import static io.servicetalk.http.netty.HttpProtocolConfigs.h1Default; import static io.servicetalk.http.netty.HttpProtocolConfigs.h2Default; -import static io.servicetalk.http.netty.HttpServers.forAddress; import static io.servicetalk.traffic.resilience.http.NoOpTrafficResiliencyObserver.NO_OP_TICKET_OBSERVER; import static io.servicetalk.transport.api.ServiceTalkSocketOptions.CONNECT_TIMEOUT; import static io.servicetalk.transport.api.ServiceTalkSocketOptions.SO_BACKLOG; import static io.servicetalk.transport.netty.internal.AddressUtils.localAddress; import static io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort; -import static java.lang.Boolean.parseBoolean; import static java.util.concurrent.TimeUnit.SECONDS; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; @@ -85,8 +84,6 @@ class TrafficResilienceHttpServiceFilterTest { private static final boolean IS_LINUX = "linux".equals(normalizedOs()); - private static final boolean CI = parseBoolean(System.getenv("CI")); - // There is an off-by-one behavior difference between macOS & Linux. // Linux has a greater-than check // (see. https://github.com/torvalds/linux/blob/5bfc75d92efd494db37f5c4c173d3639d4772966/include/net/sock.h#L941) @@ -104,8 +101,8 @@ void verifyPeerRejectionCallbacks() throws Exception { final AtomicInteger consumption = new AtomicInteger(); // Expect two state changes final CountDownLatch latch = new CountDownLatch(2); - try (ServerContext serverContext = HttpServers.forPort(0).listenAndAwait((ctx, request, responseFactory) -> - succeeded(responseFactory.serviceUnavailable()))) { + try (ServerContext serverContext = HttpServers.forAddress(localAddress(0)) + .listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.serviceUnavailable())) { final TrafficResilienceHttpClientFilter trafficResilienceHttpClientFilter = new TrafficResilienceHttpClientFilter.Builder(() -> CapacityLimiters.fixedCapacity(1) .stateObserver((capacity, consumed) -> { @@ -226,7 +223,7 @@ void testStopAcceptingConnections(final boolean dryRun, final String protocol) t .dryRun(dryRun) .build(); - final HttpServerContext serverContext = forAddress(localAddress(0)) + final HttpServerContext serverContext = HttpServers.forAddress(localAddress(0)) .protocols(protocolConfig) .listenSocketOption(SO_BACKLOG, TCP_BACKLOG) .appendNonOffloadingServiceFilter(filter) From 57c877b68d53bd304c477fc1f0eb0afdd00eaaf4 Mon Sep 17 00:00:00 2001 From: Idel Pivnitskiy Date: Fri, 8 Nov 2024 19:41:11 -0800 Subject: [PATCH 2/2] fix checkstyle --- .../resilience/http/TrafficResilienceHttpServiceFilterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/servicetalk-traffic-resilience-http/src/test/java/io/servicetalk/traffic/resilience/http/TrafficResilienceHttpServiceFilterTest.java b/servicetalk-traffic-resilience-http/src/test/java/io/servicetalk/traffic/resilience/http/TrafficResilienceHttpServiceFilterTest.java index 6efe0acc96..e37315fc5b 100644 --- a/servicetalk-traffic-resilience-http/src/test/java/io/servicetalk/traffic/resilience/http/TrafficResilienceHttpServiceFilterTest.java +++ b/servicetalk-traffic-resilience-http/src/test/java/io/servicetalk/traffic/resilience/http/TrafficResilienceHttpServiceFilterTest.java @@ -56,8 +56,8 @@ import static io.servicetalk.capacity.limiter.api.CapacityLimiters.fixedCapacity; import static io.servicetalk.concurrent.api.Single.succeeded; import static io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION; -import static io.servicetalk.http.api.HttpProtocolVersion.HTTP_1_1; import static io.servicetalk.concurrent.internal.TestTimeoutConstants.CI; +import static io.servicetalk.http.api.HttpProtocolVersion.HTTP_1_1; import static io.servicetalk.http.netty.AsyncContextHttpFilterVerifier.verifyServerFilterAsyncContextVisibility; import static io.servicetalk.http.netty.HttpProtocolConfigs.h1Default; import static io.servicetalk.http.netty.HttpProtocolConfigs.h2Default;