Skip to content

Commit

Permalink
Merge pull request square#1720 from square/jwilson_0621_sane_timeouts
Browse files Browse the repository at this point in the history
Set default timeouts to ten seconds.
  • Loading branch information
JakeWharton committed Jun 22, 2015
2 parents 832038b + 0de14e9 commit f0df400
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public final class OkHttpClientTest {
Authenticator.setDefault(DEFAULT_AUTHENTICATOR);
}

@Test public void timeoutDefaults() {
OkHttpClient client = new OkHttpClient();
assertEquals(10_000, client.getConnectTimeout());
assertEquals(10_000, client.getReadTimeout());
assertEquals(10_000, client.getWriteTimeout());
}

@Test public void timeoutValidRange() {
OkHttpClient client = new OkHttpClient();
try {
Expand Down Expand Up @@ -89,9 +96,9 @@ public final class OkHttpClientTest {
@Test public void copyWithDefaultsWhenDefaultIsAConstant() throws Exception {
OkHttpClient client = new OkHttpClient().copyWithDefaults();
assertNull(client.internalCache());
assertEquals(0, client.getConnectTimeout());
assertEquals(0, client.getReadTimeout());
assertEquals(0, client.getWriteTimeout());
assertEquals(10_000, client.getConnectTimeout());
assertEquals(10_000, client.getReadTimeout());
assertEquals(10_000, client.getWriteTimeout());
assertTrue(client.getFollowSslRedirects());
assertNull(client.getProxy());
assertEquals(Arrays.asList(Protocol.HTTP_2, Protocol.SPDY_3, Protocol.HTTP_1_1),
Expand Down
6 changes: 3 additions & 3 deletions okhttp/src/main/java/com/squareup/okhttp/OkHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ public void apply(ConnectionSpec tlsConfiguration, SSLSocket sslSocket, boolean
private boolean followSslRedirects = true;
private boolean followRedirects = true;
private boolean retryOnConnectionFailure = true;
private int connectTimeout;
private int readTimeout;
private int writeTimeout;
private int connectTimeout = 10_000;
private int readTimeout = 10_000;
private int writeTimeout = 10_000;

public OkHttpClient() {
routeDatabase = new RouteDatabase();
Expand Down

0 comments on commit f0df400

Please sign in to comment.