aboutsummaryrefslogtreecommitdiff
path: root/mockwebserver
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2015-11-09 13:16:23 +0000
committerNeil Fuller <nfuller@google.com>2015-11-09 13:16:23 +0000
commitd22dae2ff3c14d458829d7082651f3e6baa9b65d (patch)
tree56868da57af5dd63ce07cd2f99eaa9c3c69d41eb /mockwebserver
parentc03aecac9ba8a7acc0ec7258ab76ec6ee2e9d84b (diff)
downloadokhttp-d22dae2ff3c14d458829d7082651f3e6baa9b65d.tar.gz
Fix URLConnectionTest.writeTimeouts with large receive buffers
This is upstream okhttp commit 8b19bc471f66ee45c5eed3df6817411d074aabe5. https://github.com/square/okhttp/commit/8b19bc471f66ee45c5eed3df6817411d074aabe5 back-ported to Android's version of OkHttp. From the upstream commit: The test relies on small client send / server receive buffers to force blocking and generate a timeout. The switch to make MockWebServer a @Rule (commit 785d9e94387f404f571775a49c3a9438508bb659) moved the MockWebServer.start() call earlier in the test execution. Setting the ServerSocketFactory became a no-op so the server receive buffer size was left as the default. The test became reliant on either: 1) The default server socket receive buffer being small enough (e.g. less than the data being transmitted). 2) The device being too slow to send the requested data in the time allowed. The test was recently made less reliable by: 1) The okio commit f30955cb15eb234f874dd55819686832c960765b, which made the segment size bigger (increasing throughput / transfer efficiency). 2) The OkHttp commit f30955cb15eb234f874dd55819686832c960765b, which reduced the amount of data being sent in the test from 16MB to 2MB. 3) Recent Android devices have large default buffer sizes. e.g. Nexus 5: 1MB, Nexus 5X: 6MB. Bug: 25459708 Change-Id: Icaa3255d86d228302931baca0432ea9a5be1e7f0
Diffstat (limited to 'mockwebserver')
-rw-r--r--mockwebserver/src/main/java/com/squareup/okhttp/mockwebserver/MockWebServer.java2
1 files changed, 2 insertions, 0 deletions
diff --git a/mockwebserver/src/main/java/com/squareup/okhttp/mockwebserver/MockWebServer.java b/mockwebserver/src/main/java/com/squareup/okhttp/mockwebserver/MockWebServer.java
index 458c6f9..0e746d3 100644
--- a/mockwebserver/src/main/java/com/squareup/okhttp/mockwebserver/MockWebServer.java
+++ b/mockwebserver/src/main/java/com/squareup/okhttp/mockwebserver/MockWebServer.java
@@ -174,6 +174,8 @@ public final class MockWebServer implements TestRule {
}
public void setServerSocketFactory(ServerSocketFactory serverSocketFactory) {
+ if (executor != null) throw new IllegalStateException(
+ "setServerSocketFactory() must be called before start()");
this.serverSocketFactory = serverSocketFactory;
}