diff options
author | Neil Fuller <nfuller@google.com> | 2015-02-09 15:46:01 +0000 |
---|---|---|
committer | Neil Fuller <nfuller@google.com> | 2015-02-09 15:53:35 +0000 |
commit | 75a7afac9b6b5866cde46c3d3158227391175701 (patch) | |
tree | cf6b0abccb56ce7c2e1324c12f9e27e70c35d49d | |
parent | 342d21a7eb7d28ae132c43a4ab8353cbedff9e01 (diff) | |
download | okhttp-lollipop-mr1-dev.tar.gz |
Reduce flakiness of OkHttp testsandroid-cts-5.1_r1android-5.1.1_r5android-5.1.1_r28android-5.1.1_r22android-5.1.1_r17android-5.1.1_r12lollipop-mr1-wfc-releaselollipop-mr1-dev
Copy of the test changes from a pending upstream
pull-request:
https://github.com/square/okhttp/pull/1348
----
Android has been receiving reports of some tests being flaky
on what are probably lower-spec devices.
This introduces delays into tests where sockets are being
poisoned after the entire response body has been written to
them *and* where there are follow-up requests.
Bug: 18953235
Change-Id: Ic2d281a3faad6082819ef6d57b3489bcd6dbd474
-rw-r--r-- | okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java index 1d2e2bb..0fcc4bd 100644 --- a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java +++ b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java @@ -430,6 +430,11 @@ public final class URLConnectionTest { HttpURLConnection connection1 = client.open(server.getUrl("/a")); connection1.setReadTimeout(100); assertContent("This connection won't pool properly", connection1); + + // Give the server time to enact the socket policy if it's one that could happen after the + // client has received the response. + Thread.sleep(500); + assertEquals(0, server.takeRequest().getSequenceNumber()); HttpURLConnection connection2 = client.open(server.getUrl("/b")); connection2.setReadTimeout(100); @@ -687,6 +692,10 @@ public final class URLConnectionTest { client.setHostnameVerifier(new RecordingHostnameVerifier()); assertContent("abc", client.open(server.getUrl("/"))); + + // Give the server time to disconnect. + Thread.sleep(500); + assertContent("def", client.open(server.getUrl("/"))); RecordedRequest request1 = server.takeRequest(); @@ -1279,6 +1288,9 @@ public final class URLConnectionTest { // Seed the pool with a bad connection. assertContent("a", client.open(server.getUrl("/"))); + // Give the server time to disconnect. + Thread.sleep(500); + // This connection will need to be recovered. When it is, transparent gzip should still work! assertContent("b", client.open(server.getUrl("/"))); @@ -2630,6 +2642,9 @@ public final class URLConnectionTest { assertContent("A", client.open(server.getUrl("/a"))); + // Give the server time to disconnect. + Thread.sleep(500); + // If the request body is larger than OkHttp's replay buffer, the failure may still occur. byte[] requestBody = new byte[requestSize]; new Random(0).nextBytes(requestBody); |