aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2014-10-06 10:46:55 +0100
committerNeil Fuller <nfuller@google.com>2014-10-15 14:02:50 +0100
commit80dc43a961235f35dd6859e6375c84825a5986e0 (patch)
tree777cf754c603530c294848d2897a332597b230ff
parent2ef5d26d620c505a2ce83f6ff580cccd66242a04 (diff)
downloadokhttp-80dc43a961235f35dd6859e6375c84825a5986e0.tar.gz
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
-rw-r--r--okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/ThreadInterruptTest.java5
1 files changed, 3 insertions, 2 deletions
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.InterruptedIOException;
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 @@ public final class ThreadInterruptTest {
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 @@ public final class ThreadInterruptTest {
}
@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])