From 5d56601f34dc40a98c66488025e0bc97a2fcc670 Mon Sep 17 00:00:00 2001 From: Amir Livneh Date: Tue, 25 Dec 2018 12:16:41 -0500 Subject: [PATCH] Test call timeout after following redirect on a new connection Reproduces a bug where call timeout is not fired after following a redirect on a new connection. --- .../okhttp3/WholeOperationTimeoutTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/okhttp-tests/src/test/java/okhttp3/WholeOperationTimeoutTest.java b/okhttp-tests/src/test/java/okhttp3/WholeOperationTimeoutTest.java index 603f22139..5947b7ddd 100644 --- a/okhttp-tests/src/test/java/okhttp3/WholeOperationTimeoutTest.java +++ b/okhttp-tests/src/test/java/okhttp3/WholeOperationTimeoutTest.java @@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicReference; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okio.BufferedSink; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; @@ -256,6 +257,31 @@ public final class WholeOperationTimeoutTest { } } + @Ignore( + "timeout.exit() is called when the first connection is released but timeout.enter() is not called again") + @Test + public void timeoutFollowingRedirectOnNewConnection() throws Exception { + MockWebServer otherServer = new MockWebServer(); + + server.enqueue( + new MockResponse() + .setResponseCode(HttpURLConnection.HTTP_MOVED_TEMP) + .setHeader("Location", otherServer.url("/"))); + + otherServer.enqueue(new MockResponse().setHeadersDelay(500, TimeUnit.MILLISECONDS)); + + Request request = new Request.Builder().url(server.url("/")).build(); + + Call call = client.newCall(request); + call.timeout().timeout(250, TimeUnit.MILLISECONDS); + try { + Response response = call.execute(); + fail(); + } catch (IOException e) { + assertTrue(call.isCanceled()); + } + } + @Test public void noTimeout() throws Exception { server.enqueue(new MockResponse() .setHeadersDelay(250, TimeUnit.MILLISECONDS)