Fix OkHttp test failure for fast devices
On a fast device the ThreadInterruptTest#interruptWritingRequestBody
would consistently fail.
The issue is probably a combination of socket buffering and the data
volume chosen by the test. The test was written to assume that
read-side throttling would prevent the writer from writing its data
within 500 millis. After ~500 millis the write thread would be
interrupted and the test would pass.
On a fast device the test would write all the test data
in ~ 125 millis and the test would fail. The interruption would then
trigger on a later test
(typically URLConnectionTest#authenticateWithGetAndTransparentGzip),
breaking that test as well.
If there is sufficient socket-level read/write buffering it is
possible the data being written will just fill the socket buffers
and the writer will terminate early. If the data to be written is
increased from 2 to 10 MB the test passes.
Bug: 17516838
(cherry-picked from commit e3bfefb13c93006a2fbe22363572a314f6c18659)
Change-Id: Id832c366611d19a0e771b5dfb58a716b17221f95
diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/ThreadInterruptTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/ThreadInterruptTest.java
index bbb7715..7e7ce0b 100644
--- a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/ThreadInterruptTest.java
+++ b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/ThreadInterruptTest.java
@@ -23,6 +23,7 @@
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.util.concurrent.TimeUnit;
+
import org.junit.Test;
import static org.junit.Assert.fail;
@@ -32,7 +33,7 @@
private final OkHttpClient client = new OkHttpClient();
@Test public void interruptWritingRequestBody() throws Exception {
- int requestBodySize = 2 * 1024 * 1024; // 2 MiB
+ int requestBodySize = 10 * 1024 * 1024; // 10 MiB
server.enqueue(new MockResponse()
.throttleBody(64 * 1024, 125, TimeUnit.MILLISECONDS)); // 500 Kbps
@@ -58,7 +59,7 @@
}
@Test public void interruptReadingResponseBody() throws Exception {
- int responseBodySize = 2 * 1024 * 1024; // 2 MiB
+ int responseBodySize = 10 * 1024 * 1024; // 10 MiB
server.enqueue(new MockResponse()
.setBody(new byte[responseBodySize])