diff options
author | Sorin Basca <sorinbasca@google.com> | 2021-07-19 14:16:33 +0000 |
---|---|---|
committer | Sorin Basca <sorinbasca@google.com> | 2021-07-20 11:26:55 +0000 |
commit | 35aef1ba398a2b1dd2ff0bc20fa6203a9e32ba85 (patch) | |
tree | 639b7105d88707c56681b42e879c6ba129998b11 | |
parent | 541335a9306579edf064d1be862192891697050d (diff) | |
download | okhttp-35aef1ba398a2b1dd2ff0bc20fa6203a9e32ba85.tar.gz |
Fixing stability of CallTest.cancelInFlightBeforeResponseReadThrowsIOEandroid12-dev
The CallTest.cancelInFlightBeforeResponseReadThrowsIOE tests fail
occasionally. It looks like a race condition between the cancel
going through and the response message being handled from the
client side.
The test code has been updated to make the server-side hold off
the response until the cancel is seen on the client-side.
(cherry picked from commit 6bb2abab50a48217af33c9872ead82ba507f0ffa)
Bug: 191957489
Test: atest CtsLibcoreOkHttpTestCases:com.squareup.okhttp.CallTest --iterations 1000
Merged-In: Ic9a8a0ef59723baa08b44ad9db0dc5c695ba9578
Change-Id: Ic9a8a0ef59723baa08b44ad9db0dc5c695ba9578
-rw-r--r-- | okhttp-tests/src/test/java/com/squareup/okhttp/CallTest.java | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/CallTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/CallTest.java index 3d48658..0b18783 100644 --- a/okhttp-tests/src/test/java/com/squareup/okhttp/CallTest.java +++ b/okhttp-tests/src/test/java/com/squareup/okhttp/CallTest.java @@ -1650,9 +1650,16 @@ public final class CallTest { } @Test public void cancelInFlightBeforeResponseReadThrowsIOE() throws Exception { + final CountDownLatch cancelSignal = new CountDownLatch(1); + server.setDispatcher(new Dispatcher() { @Override public MockResponse dispatch(RecordedRequest request) { client.cancel("request"); + try { + cancelSignal.await(10L, TimeUnit.SECONDS); + } catch (InterruptedException e) { + // Do nothing + } return new MockResponse().setBody("A"); } }); @@ -1662,6 +1669,7 @@ public final class CallTest { client.newCall(request).execute(); fail(); } catch (IOException expected) { + cancelSignal.countDown(); } } |