From 35aef1ba398a2b1dd2ff0bc20fa6203a9e32ba85 Mon Sep 17 00:00:00 2001 From: Sorin Basca Date: Mon, 19 Jul 2021 14:16:33 +0000 Subject: Fixing stability of CallTest.cancelInFlightBeforeResponseReadThrowsIOE 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 --- okhttp-tests/src/test/java/com/squareup/okhttp/CallTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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(); } } -- cgit v1.2.3