Maybe DEFAULT_TEST_TIMEOUT or TEST_TIMEOUT instead of TIMEOUT would be clearer?
Gary ---------- Forwarded message ---------- From: <[email protected]> Date: Sat, Sep 2, 2017 at 9:00 AM Subject: httpcomponents-client git commit: Consistent timeout settings in integration tests To: [email protected] Repository: httpcomponents-client Updated Branches: refs/heads/master dcc09e92e -> b4e0611b0 Consistent timeout settings in integration tests Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents- client/commit/b4e0611b Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents- client/tree/b4e0611b Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents- client/diff/b4e0611b Branch: refs/heads/master Commit: b4e0611b05e82c042871166e2546f0100d29b102 Parents: dcc09e9 Author: Oleg Kalnichevski <[email protected]> Authored: Sat Sep 2 16:49:42 2017 +0200 Committer: Oleg Kalnichevski <[email protected]> Committed: Sat Sep 2 16:52:24 2017 +0200 ---------------------------------------------------------------------- .../client5/testing/async/IntegrationTestBase.java | 9 ++++++++- .../testing/async/LocalAsyncServerTestBase.java | 8 +++++++- .../async/TestAsyncStatefulConnManagement.java | 2 +- .../client5/testing/async/TestHttpAsyncMinimal.java | 9 +++++++-- .../hc/client5/testing/sync/LocalServerTestBase.java | 15 ++++++++++++--- .../testing/sync/TestStatefulConnManagement.java | 2 +- 6 files changed, 36 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/b4e0611b/ httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ IntegrationTestBase.java ---------------------------------------------------------------------- diff --git a/httpclient5-testing/src/test/java/org/apache/hc/ client5/testing/async/IntegrationTestBase.java b/httpclient5-testing/src/ test/java/org/apache/hc/client5/testing/async/IntegrationTestBase.java index 4ba9ce1..3180227 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ IntegrationTestBase.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ IntegrationTestBase.java @@ -30,6 +30,7 @@ package org.apache.hc.client5.testing.async; import java.net.InetSocketAddress; import java.util.concurrent.Future; +import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder; import org.apache.hc.core5.function.Decorator; @@ -62,7 +63,13 @@ public abstract class IntegrationTestBase extends LocalAsyncServerTestBase { @Override protected void before() throws Throwable { - clientBuilder = HttpAsyncClientBuilder.create( ).setConnectionManager(connManager); + clientBuilder = HttpAsyncClientBuilder.create() + .setDefaultRequestConfig(RequestConfig.custom() + .setSocketTimeout(TIMEOUT) + .setConnectTimeout(TIMEOUT) + .setConnectionRequestTimeout(TIMEOUT) + .build()) + .setConnectionManager(connManager); } @Override http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/b4e0611b/ httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ LocalAsyncServerTestBase.java ---------------------------------------------------------------------- diff --git a/httpclient5-testing/src/test/java/org/apache/hc/ client5/testing/async/LocalAsyncServerTestBase.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ LocalAsyncServerTestBase.java index 71795ad..5ae533c 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ LocalAsyncServerTestBase.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ LocalAsyncServerTestBase.java @@ -37,11 +37,15 @@ import org.apache.hc.core5.http.nio. AsyncServerExchangeHandler; import org.apache.hc.core5.reactor.IOReactorConfig; import org.apache.hc.core5.testing.nio.Http2TestServer; import org.apache.hc.core5.util.TimeValue; +import org.apache.hc.core5.util.Timeout; import org.junit.Rule; import org.junit.rules.ExternalResource; public abstract class LocalAsyncServerTestBase { + public static final Timeout TIMEOUT = Timeout.ofSeconds(30); + public static final Timeout LONG_TIMEOUT = Timeout.ofSeconds(60); + protected final URIScheme scheme; public LocalAsyncServerTestBase(final URIScheme scheme) { @@ -61,7 +65,9 @@ public abstract class LocalAsyncServerTestBase { @Override protected void before() throws Throwable { server = new Http2TestServer( - IOReactorConfig.DEFAULT, + IOReactorConfig.custom() + .setSoTimeout(TIMEOUT) + .build(), scheme == URIScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null); server.register("/echo/*", new Supplier<AsyncServerExchangeHandler>() { http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/b4e0611b/ httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ TestAsyncStatefulConnManagement.java ---------------------------------------------------------------------- diff --git a/httpclient5-testing/src/test/java/org/apache/hc/ client5/testing/async/TestAsyncStatefulConnManagement.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ TestAsyncStatefulConnManagement.java index 39e6750..4e27593 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ TestAsyncStatefulConnManagement.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ TestAsyncStatefulConnManagement.java @@ -97,7 +97,7 @@ public class TestAsyncStatefulConnManagement extends IntegrationTestBase { worker.start(); } for (final HttpWorker worker : workers) { - worker.join(10000); + worker.join(LONG_TIMEOUT.toMillis()); } for (final HttpWorker worker : workers) { final Exception ex = worker.getException(); http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/b4e0611b/ httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ TestHttpAsyncMinimal.java ---------------------------------------------------------------------- diff --git a/httpclient5-testing/src/test/java/org/apache/hc/ client5/testing/async/TestHttpAsyncMinimal.java b/httpclient5-testing/src/ test/java/org/apache/hc/client5/testing/async/TestHttpAsyncMinimal.java index 5ae7fe7..97e3acb 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ TestHttpAsyncMinimal.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ TestHttpAsyncMinimal.java @@ -64,6 +64,7 @@ import org.apache.hc.core5.reactor.IOReactorConfig; import org.apache.hc.core5.reactor.ListenerEndpoint; import org.apache.hc.core5.testing.nio.Http2TestServer; import org.apache.hc.core5.util.TimeValue; +import org.apache.hc.core5.util.Timeout; import org.hamcrest.CoreMatchers; import org.junit.Assert; import org.junit.Rule; @@ -75,6 +76,8 @@ import org.junit.runners.Parameterized; @RunWith(Parameterized.class) public class TestHttpAsyncMinimal { + public static final Timeout TIMEOUT = Timeout.ofSeconds(30); + @Parameterized.Parameters(name = "{0} {1}") public static Collection<Object[]> protocols() { return Arrays.asList(new Object[][]{ @@ -102,7 +105,9 @@ public class TestHttpAsyncMinimal { @Override protected void before() throws Throwable { server = new Http2TestServer( - IOReactorConfig.DEFAULT, + IOReactorConfig.custom() + .setSoTimeout(TIMEOUT) + .build(), scheme == URIScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null); server.register("/echo/*", new Supplier<AsyncServerExchangeHandler>() { @@ -141,7 +146,7 @@ public class TestHttpAsyncMinimal { .setTlsStrategy(new H2TlsStrategy(SSLTestContexts. createClientSSLContext())) .build(); final IOReactorConfig ioReactorConfig = IOReactorConfig.custom() - .setSoTimeout(5, TimeUnit.SECONDS) + .setSoTimeout(TIMEOUT) .build(); if (version.greaterEquals(HttpVersion.HTTP_2)) { httpclient = HttpAsyncClients.createMinimal( http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/b4e0611b/ httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/ LocalServerTestBase.java ---------------------------------------------------------------------- diff --git a/httpclient5-testing/src/test/java/org/apache/hc/ client5/testing/sync/LocalServerTestBase.java b/httpclient5-testing/src/ test/java/org/apache/hc/client5/testing/sync/LocalServerTestBase.java index 85f8ab2..ae71dba 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/ LocalServerTestBase.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/ LocalServerTestBase.java @@ -28,8 +28,8 @@ package org.apache.hc.client5.testing.sync; import java.io.IOException; -import java.util.concurrent.TimeUnit; +import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionMan ager; import org.apache.hc.client5.http.impl.sync.CloseableHttpClient; import org.apache.hc.client5.http.impl.sync.HttpClientBuilder; @@ -44,6 +44,7 @@ import org.apache.hc.core5.http.io. HttpServerRequestHandler; import org.apache.hc.core5.http.protocol.HttpProcessor; import org.apache.hc.core5.io.ShutdownType; import org.apache.hc.core5.testing.classic.ClassicTestServer; +import org.apache.hc.core5.util.Timeout; import org.junit.Rule; import org.junit.rules.ExternalResource; @@ -52,6 +53,9 @@ import org.junit.rules.ExternalResource; */ public abstract class LocalServerTestBase { + public static final Timeout TIMEOUT = Timeout.ofSeconds(30); + public static final Timeout LONG_TIMEOUT = Timeout.ofSeconds(60); + public LocalServerTestBase(final URIScheme scheme) { this.scheme = scheme; } @@ -72,7 +76,7 @@ public abstract class LocalServerTestBase { server = new ClassicTestServer( scheme == URIScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null, SocketConfig.custom() - .setSoTimeout(5, TimeUnit.SECONDS) + .setSoTimeout(TIMEOUT) .build()); server.registerHandler("/echo/*", new EchoHandler()); server.registerHandler("/random/*", new RandomHandler()); @@ -102,9 +106,14 @@ public abstract class LocalServerTestBase { protected void before() throws Throwable { connManager = new PoolingHttpClientConnectionManager(); connManager.setDefaultSocketConfig(SocketConfig.custom() - .setSoTimeout(5, TimeUnit.SECONDS) + .setSoTimeout(TIMEOUT) .build()); clientBuilder = HttpClientBuilder.create() + .setDefaultRequestConfig(RequestConfig.custom() + .setSocketTimeout(TIMEOUT) + .setConnectTimeout(TIMEOUT) + .setConnectionRequestTimeout(TIMEOUT) + .build()) .setConnectionManager(connManager); } http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/b4e0611b/ httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/ TestStatefulConnManagement.java ---------------------------------------------------------------------- diff --git a/httpclient5-testing/src/test/java/org/apache/hc/ client5/testing/sync/TestStatefulConnManagement.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/ TestStatefulConnManagement.java index 73a36cc..a31b039 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/ TestStatefulConnManagement.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/ TestStatefulConnManagement.java @@ -107,7 +107,7 @@ public class TestStatefulConnManagement extends LocalServerTestBase { worker.start(); } for (final HttpWorker worker : workers) { - worker.join(10000); + worker.join(LONG_TIMEOUT.toMillis()); } for (final HttpWorker worker : workers) { final Exception ex = worker.getException();
