• Home
  • History
  • Annotate
  • only in /external/okhttp/okhttp-tests/src/test/java/com/squareup/
History log of /external/okhttp/okhttp-tests/src/test/java/com/squareup/
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
75a7afac9b6b5866cde46c3d3158227391175701 09-Feb-2015 Neil Fuller <nfuller@google.com> Reduce flakiness of OkHttp tests

Copy of the test changes from a pending upstream


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
342d21a7eb7d28ae132c43a4ab8353cbedff9e01 11-Dec-2014 Neil Fuller <nfuller@google.com> Fix DisconnectTest for devices with large socket buffers

Similar to commit e3bfefb13c93006a2fbe22363572a314f6c18659
but for DisconnectTest. The buffer sizes are large on some
devices so the expectation that they take a lot of time to
stream data is invalid because they just write into the

Bug: 18703696
Change-Id: I6127b044bf7fefc192f577d0b035deacbc54dd5f
dd6543e08d4d139de53b51753ceb2dffea93beac 10-Dec-2014 Neil Fuller <nfuller@google.com> Merge "Avoid a reverse DNS-lookup for a numeric proxy address" into lmp-mr1-dev
2ed0095a4f0da2f0bbe75b9d139419ce75afaa25 02-Dec-2014 Neil Fuller <nfuller@google.com> Avoid a reverse DNS-lookup for a numeric proxy address

When the proxy is specified as an IP address the RouteSelector
would force a reverse-lookup. This can introduce extra latency
when the DNS is slow or missing. It also then turns the name
back into a set of IPs, which may result in the original IP
address not being given priority.

This is upstream commit:

Bug: 18567569
Bug: 18327075
(cherry picked from commit 797fdc6cc6bf16372e9464f189b535148f944ce9)

Change-Id: I52b4049095acafd2367530532d8cad7d75b6809a
afcb40207ecf7fc935b40a76cd0c039d5e576441 02-Dec-2014 Neil Fuller <nfuller@google.com> am 0f102f51: Add further handling for when a CONNECT incorrectly returns a body.

* commit '0f102f51711ecc2ef9f25cbbad2148ee97bdb6cb':
Add further handling for when a CONNECT incorrectly returns a body.
0f102f51711ecc2ef9f25cbbad2148ee97bdb6cb 05-Nov-2014 Neil Fuller <nfuller@google.com> Add further handling for when a CONNECT incorrectly returns a body.

Before the change:
If a proxy returns a body and some of the body bytes have
already been buffered then an IOException is thrown.
If the body bytes have not been buffered then the handshake will
fail due to the presence of bytes where the Server HELLO is
expected, typically with some kind of SSLHandshakeException.

After the change:
The body bytes are consumed to ensure consistent behavior. The
handshake will then take place.

This is an unusual case that would occasionally cause failures
on Android when a ResponseCache was installed. Android introduced
a patch to prevent CONNECT responses being cached. Since then,
OkHttp has changed the code and probably fixed the issue via
other means. The Android test remained and would sometimes
experience one exception, sometimes another, depending on the
state of the buffer.

If the presence of a body is a possibility it would be nice
to deal with it consistently and deterministically.

The motivation for this change is to make an Android test
equivalent to the one added here behave consistently and in a
way that doesn't involve connection fallback.

The only risk with this change is if a proxy is incorrectly
reporting the content length: this might lead to blocking on
the body read/skip (as OkHttp would probably do elsewhere if a
server mis-reports a content-length). This may make connections
to "bad" proxies slightly more reliable.

Bug: 6754912
Bug: 18575971

(cherry picked from commit 007b88ad6df622a2e5daacce604637d006ed6212)

Change-Id: Icf9e17a26dd2b1c4024935dfae3e87b2654a220e
00407a766d802a365a2025add7ce89be46548da4 20-Nov-2014 Neil Fuller <nfuller@google.com> Merge "Fix for a socket leak in OkHttp on Android" into lmp-mr1-dev
f3bcd0c7f0741b277b5d58f294df6201dafd45e8 19-Nov-2014 Neil Fuller <nfuller@google.com> Fix for a socket leak in OkHttp on Android

When the preferred Android network changes from
cell -> wifi or wifi -> cell the HTTP connection
pool in use is abandoned to avoid reuse of
connections on the old network. This was added
in commit 8bced3e.

The design for the connection pool was such that
continuous use of the connection pool was required to
clean up idle / expired connections. If a connection
pool becomes idle (as when it is dereferenced on a
network change) it is possible for some connections
to remain in the pool indefinitely.

After the preferred network change, because the old
connection pool was no longer referenced the pool
would be garbage collected and Android's "Strict Mode"
would complain about sockets not being closed.

The only existing way to avoid this was to call
"evictAll()", which would have had issues when a
large number of connections were returned to the pool
after evictAll() was called. It also wouldn't work
for SPDY connections which are shared but not reference
counted, which makes knowing whether it is safe to
close them difficult. SPDY is not enabled on Android
by default and so that may have been safe to ignore.

This fix tries to keep the existing cleaning behavior
intact to avoid introducing new bugs or new thread
behavior that might impact battery life. It adds a
new mode to the pool for "draining", which handles
cleaning up any existing entries in the pool and any
added after the pool has been placed into draining

The drainModeRunnable introduced serves two purposes:

1) While scheduled / executing, it pins the connection
pool in memory to avoid it being garbage collected.
2) It continues to close connections (safely) until the
pool is empty.

If a connection is then added back to the pool the
drainModeRunnable is restarted.

Bug: 18369687
(cherry picked from commit ff345b6c0ffcc691e4c3c594f8a222cf81bb325c)

Change-Id: I4e9e530f8e7acedf4b9a806237c8769a10671feb
466ef072d672d6c5cce3da222f76828427680e53 19-Nov-2014 Alex Klyubin <klyubin@google.com> am db7edbf1: am 200d28a2: am e82a7960: Fix a bug in OkHostnameVerifier wildcard handling.

* commit 'db7edbf1f7713d5170a8132c0d1a3c43f90f55e5':
Fix a bug in OkHostnameVerifier wildcard handling.
a03ec4ced2b11f9eae6cbeeedb1db2b1b29fafb1 19-Nov-2014 Alex Klyubin <klyubin@google.com> Fix a bug in OkHostnameVerifier wildcard handling.

Wildcard domain name patterns of the form *.remainder are supposed to
match domain names that exactly match the remainder. Due to a bug,
the match was not exact but rather a prefix match: domain names
starting with the remainder would match too.

This CL fixes the issue.

Bug: 18432707
Change-Id: I2639ff51cabcbd395d4f30a9c69f9895738e0acf
602d5e4cfdbd0bad91e7872837f95aff5b461595 03-Apr-2014 Jesse Wilson <jwilson@squareup.com> New disconnect strategy.

Support asynchronous disconnects by breaking the socket only, which
should cause the thread using that socket to trigger clean-up.

Upstream commit: https://github.com/square/okhttp/commit/9c302131491d05a4ca0209ef21770592c01f76fa

Bug: 18083851
(cherry picked from commit 87ed7244fb53ae2bac9f23c033bbd5f23ac269f8)

Change-Id: Ia16147cb84eb9e73af48a2771ef734fbb7baa8f5
95d1a1316ee04d39d55102e65daaacb97f5d42f8 13-Oct-2014 Neil Fuller <nfuller@google.com> Fixing broken OkHttp CTS test

Bug: 17962997
Bug: 17750026
Change-Id: Icbc48a8c30857b3afb0175ac4b341626d4b3dfe8
e3bfefb13c93006a2fbe22363572a314f6c18659 06-Oct-2014 Neil Fuller <nfuller@google.com> 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
Change-Id: I54b5de9527d9737e6c987b6a9c4f62578f4f8fb7
2ee29995b7bd1068991884a54ca14e9aeeff1a58 30-Jul-2014 Neil Fuller <nfuller@google.com> Fix transparent gzip for basic auth.

Externally reported Android bug:

Thanks to mattpan91 for the report.

The issue was fixed in OkHttp 2.0. It has now been back-ported to 1.6.

This is a cherry pick from the okhttp_16 branch:

The merge was not entirely straightforward: Android is currently not quite
on 1.6; it is close and it was only the package for the files that differed
for existing files. There is an additional class (Job) that had to be patched
that the version Android has and 1.6 does not have. The class is probably not
used on Android.

The okhttp CTS tests pass, modulo some tests known to be flaky.

Bug: 16628050
Bug: https://code.google.com/p/android/issues/detail?id=74026

(cherry picked from commit f6af62d5c9bb5e15649a80ebae973463e8e2dc46)

Change-Id: I3172789a17384666eba732a7782573e08f06a48c
7c7f22d80748dc444d5da3c5be11d7d81ef14a2b 17-Jul-2014 Lorenzo Colitti <lorenzo@google.com> Allow callers to pass in a custom host resolver implementation.

An HTTP client interacts with the network in two main ways: DNS
lookups and connections to HTTP servers. OkHttp already abstracts
the latter by allowing callers to pass in custom SocketFactory
objects, but does not yet abstract the former.

This change takes the existing internal Dns interface, which is
currently used for testing, and turns it into a publicly
accessible HostResolver interface. This allows callers to
completely abstract all network interaction points.

Examples of what this can be used for:

1. Use alternative DNS implementations with different
performance / caching / ordering / parallelization / ...
characteristics than standard InetAddress.getAllByName.
2. Resolve hosts using different DNS servers than the system
resolvers, or even non-DNS protocols (e.g., MDNS or even
NetBIOS/WINS) that are not supported by the system resolver.
3. Do DNS lookups on specific networks, similarly to what
android_getaddrinfofornet does.

Backport of upstream change:

Change-Id: I6e488acd938067e4c078c6ffe4d5eddb5f3951de
1410c75d4b2334521208259b69c23aeefec072d7 17-Jul-2014 Lorenzo Colitti <lorenzo@google.com> Use the socket factory for direct connections as well.

Currently, the passed-in socket factory is only used for
connections to HTTP proxies. I think this was not the intent of
the original socket factory change, because the commit message
said that the "socket factory will be used for all non-proxy
connections and HTTP proxy connections". So use it for DIRECT
connections as well.

Also add a test to check that a socket factory is used if

Cherry-pick of https://github.com/square/okhttp/commit/7f763c1a18e342dc4e2840c68ca99c175c37eb93

(cherry picked from commit a83ddf194ffbae04ce536967efff0ec72df70e10)

Change-Id: Ie3d239d8683a51a2b6ab1dc9d443886d0746e68a
3f968acf193178145e9d227f2f08b95e2d6a6c26 15-Apr-2014 Jake Wharton <jw@squareup.com> Allow specifying a socket factory for connections.

This socket factory will be used for all non-proxy connections and HTTP proxy connections.

This is a clean cherry-pick of:

That was committed about two weeks after we pulled our current
snapshot, so we would have picked this change up on the next
sync with upstream.

Bug: 11826069

(cherry picked from commit e5baca5e4c9de92820a38e60e289d07f1acaa2ef)

Change-Id: Ica683022e6963a0a4f0c3fd1a33c1b843e307c1a
78092f38ebd93018ead53a87b53118dc829cbb8a 01-Apr-2014 Neil Fuller <nfuller@google.com> Pull upstream fixes from OkHttp

This synced to commit b21b40e480cdcd09b618e399a349556de509d88d
/ master / 1st April 2014.

Notably this contains a fix for apps that bundle an older
copy of OkHttp or which call android.net.http.HttpResponseCache.get()
or android.net.http.HttpResponseCache.put().

See for details:

Change-Id: I90acd9f9946014e834ea203dbc62cdcf7bc80cc6
4944713f5c5b141966ac82973d6a31a634e8e01e 21-Mar-2014 Neil Fuller <nfuller@google.com> Pull upstream fixes from OkHttp

This synced to commit bda555ad61ef55e9ad6e4a30d2e9cfde5fc216ca
/ master / 21st March 2014.

Notably this contains a fix for apps that bundle an older
copy of OkHttp or which call android.net.http.HttpResponseCache.get()
or android.net.http.HttpResponseCache.put().

See for details:

Change-Id: I324ac76d8ee6a615c39dc8e19dc90169528ae072
c6bd683320121544811f481709b3fdbcbe9b3866 14-Mar-2014 Neil Fuller <nfuller@google.com> Upgrade OkHttp to newer code

This update includes changes up to
68affbd24d63620e1785ea847f1936760947b9ae / master /
14th March 2014.

Importantly, it contains a DiskLruCache fix which
broke several apps.

Change-Id: I8a489e6d0937a58fad10423154bad939ea4da868
3c938a3f6b61ce5e2dba0d039b03fe73b89fd26c 19-Feb-2014 Neil Fuller <nfuller@google.com> Update okhttp to a more recent commit.

Updating to upstream commit : 7b106923e078ac2435e8c8ce9d615f9903106ed8
/ 7th Mar 2014 / main branch.

The following changes were made to Android-only code:
1) HttpsHandler has been changed to deal with the fix for:
https://github.com/square/okhttp/issues/184 (commit 5d7fdba).
2) Platform.java changed to accomodate changes in okhttp Platform
method signatures.
3) .mk file updates to reflect src directory changes.

The following changes were made to OkHttp code:
1) Removal of org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
annotation from okio/src/main/java/okio/DeflaterSink.java

Change-Id: I644a883482ac7ee7d029785f110a2ca00762419b