1
0
mirror of https://github.com/square/okhttp.git synced 2025-08-07 12:42:57 +03:00

228 Commits

Author SHA1 Message Date
Yuri Schimke
8cebf9012b Cache Events (#6015)
Provide EventListener methods to understand the impact of caching.
2020-05-05 18:25:06 +01:00
Yuri Schimke
af1eadfebf Record Http2 Frames and TaskRunner optionally for Flaky tests (#6011) 2020-05-03 20:21:12 +01:00
Jesse Wilson
3ca806c24b Don't crash processing fragmented web sockets messages (#5983)
* Don't crash processing fragmented web sockets messages

Closes: https://github.com/square/okhttp/issues/5965

* Update okhttp-testing-support/src/main/kotlin/okhttp3/TestUtil.kt

Co-Authored-By: Jake Wharton <jakew@google.com>

* Update okhttp-testing-support/src/main/kotlin/okhttp3/TestUtil.kt

Co-Authored-By: Jake Wharton <jakew@google.com>

* Update okhttp-testing-support/src/main/kotlin/okhttp3/TestUtil.kt

Co-Authored-By: Jake Wharton <jakew@google.com>

Co-authored-by: Jake Wharton <jakew@google.com>
2020-04-23 23:31:36 -04:00
Jesse Wilson
64d3b079f2 Fix DiskLruCache to work on Windows
As originally designed DiskLruCache assumes an inode-like
file system, where it's fine to delete files that are
currently being read or written.

On Windows the file system forbids this, so we must be
more careful when deleting and renaming files. These
operations come up a lot internally in the cache:
 - deleting to evict an entry
 - renaming to commit a dirty file to a clean file

The workaround is simple if unsatisfying: we don't
permit concurrent reads and writes on Windows. We
can have multiple concurrent reders, or a single
writer.

One challenge in this implementation is detecting
whether we're running on Windows or a good operating
system. We deliberately don't look at System properties
here because the OS and file system may disagree, such
as when a Windows machine has an ext4 partition, or when
a Linux machine has an NTFS partition. Instead of detecting
we just attempt an edit and see what happens.

Another challenge in this implementation is what to
do when a file needs to be deleted but cannot be because
it is currently open. In such cases we now mark the
cache entry as a 'zombie'. When the files are later
closed they now check for zombie status and delete the
files if necessary. Note that it is not possible to
store a new cache entry while it is a zombie.

Closes: https://github.com/square/okhttp/issues/5761
2020-04-11 20:16:40 -04:00
Yuri Schimke
86b7ba5f2a Enable BouncyCastle on Android and add some testing (#5936) 2020-04-11 17:35:27 +01:00
Yuri Schimke
19771365f2 Rename to src/main/kotlin (#5938)
Follows the default path logic for kotlin classes.
2020-04-11 17:15:25 +01:00
Jesse Wilson
ac53284db4 Emulate Windows file system restrictions in a wrapper
This should make it possible to get DiskLruCacheTest passing on
Windows even when Windows isn't available.
2020-04-11 11:12:56 -04:00
Yuri Schimke
b3b788a942 Upgrade to Android 10 APIs when available (#5821)
* Upgrade robolectric dependency

* cleanup

* Suppress animal sniffer checks on known classes

* Update build.gradle

* Update build.gradle
2020-04-10 10:42:29 -04:00
Yuri Schimke
b48d30aa5c Move okhttp-testing-support to Kotlin (#5906)
Moving the last big block of src/main Java code (outside of Samples).
2020-04-09 07:23:43 +01:00
Yuri Schimke
e8cfef759f Force cancel all events on client (#5901) 2020-03-26 06:45:34 +00:00
Jesse Wilson
08e23fcd02 Add a canceled event to EventListener 2020-02-16 18:20:49 -05:00
Liam Newman
78016071b3 Add a windows executor to the build (#5769)
* Add a windows executor to the build

* Disable failing tests on windows

* Workaround find limitations
2020-02-05 21:09:37 -05:00
Yuri Schimke
c6ef70148b Bouncy Castle Provider working with HTTP/2 on JDK 8 (#5751) 2020-01-29 00:19:32 -06:00
Yuri Schimke
005c39b592 Fixes for bouncycastle tests 2020-01-20 22:47:13 +00:00
Yuri Schimke
bcfa004b6a Reduce platform logging for each test (#5723) 2020-01-12 23:44:34 +00:00
Jesse Wilson
c1d50e371f Upgrade Okio and some build dependencies
The new ktlint sorts imports which makes this diff large.

The new japicmp ignores 'final' modifier changes in final classes.

We adopt the Google style for checkstyle.xml.

Okio readByteString() now uses segments more aggressively, so we
need to mitigate that to avoid tracking those segments in a test.
2020-01-11 22:24:12 -05:00
Yuri Schimke
604e2705e7 Add bouncy castle platform for tests (#5695)
* Add basic bouncy castle test

* Remove other tests

* Activate platform for TLS tests
2020-01-11 10:29:17 -05:00
Yuri Schimke
3e61ce3cf0 Test Android with Play provider (#5679) 2020-01-02 07:04:58 +00:00
Jesse Wilson
a815093721 Document debug logging.
Also refine the formatting of TaskRunner logging.

Before:

    [2019-12-30 16:43:19] Q1 starting: OkHttp ConnectionPool
    [2019-12-30 16:43:19] Q1 scheduled after 300 s: OkHttp ConnectionPool
    [2019-12-30 16:43:19] Q1 finished in 94 µs: OkHttp ConnectionPool
    [2019-12-30 16:43:19] Q359 scheduled after 0 µs: OkHttp www.youtube.com applyAndAckSettings
    [2019-12-30 16:43:19] Q359 starting: OkHttp www.youtube.com applyAndAckSettings
    [2019-12-30 16:43:19] Q361 schedule canceled (queue is shutdown): OkHttp www.youtube.com onSettings
    [2019-12-30 16:43:19] Q359 finished in 382 µs: OkHttp www.youtube.com applyAndAckSettings
    [2019-12-30 16:43:20] Q1 scheduled after 0 µs: OkHttp ConnectionPool
    [2019-12-30 16:43:20] Q365 scheduled after 0 µs: OkHttp android-developers.googleblog.com applyAndAckSettings
    [2019-12-30 16:43:20] Q1 starting: OkHttp ConnectionPool
    [2019-12-30 16:43:20] Q365 starting: OkHttp android-developers.googleblog.com applyAndAckSettings
    [2019-12-30 16:43:20] Q1 scheduled after 300 s: OkHttp ConnectionPool
    [2019-12-30 16:43:20] Q1 finished in 151 µs: OkHttp ConnectionPool

After:

    [2019-12-30 16:43:19] Q10001 starting              : OkHttp ConnectionPool
    [2019-12-30 16:43:19] Q10001 run again after 300 s : OkHttp ConnectionPool
    [2019-12-30 16:43:19] Q10001 finished run in  94 µs: OkHttp ConnectionPool
    [2019-12-30 16:43:19] Q10359 scheduled after   0 µs: OkHttp www.youtube.com applyAndAckSettings
    [2019-12-30 16:43:19] Q10359 starting              : OkHttp www.youtube.com applyAndAckSettings
    [2019-12-30 16:43:19] Q10361 schedule canceled (queue is shutdown): OkHttp www.youtube.com onSettings
    [2019-12-30 16:43:19] Q10359 finished run in 382 µs: OkHttp www.youtube.com applyAndAckSettings
    [2019-12-30 16:43:20] Q10001 scheduled after   0 µs: OkHttp ConnectionPool
    [2019-12-30 16:43:20] Q10365 scheduled after   0 µs: OkHttp android-developers.googleblog.com applyAndAckSettings
    [2019-12-30 16:43:20] Q10001 starting              : OkHttp ConnectionPool
    [2019-12-30 16:43:20] Q10365 starting              : OkHttp android-developers.googleblog.com applyAndAckSettings
    [2019-12-30 16:43:20] Q10001 run again after 300 s : OkHttp ConnectionPool
    [2019-12-30 16:43:20] Q10001 finished run in 151 µs: OkHttp ConnectionPool
2019-12-31 14:21:05 -05:00
Jesse Wilson
edb5865b4c Fix crash on repeated MockWebServer shutdown
The problem was the awaitIdle() call was scheduling executor jobs after
the ExecutorService had been shut down. This fixes that and defends
against other races.
2019-12-30 23:34:42 -05:00
Jesse Wilson
53d2d794b9 Defer EventListener events until bytes are returned
This changes the timing of responseHeaderStart and responseBodyStart events to
fire when bytes are received from the server. This is a non-trivial behavior
change and should be documented as such in the release notes. In particular,
the responseFailed event may be fired without a preceding responseHeadersStart
event.

To test this I've added a timestamp to our CallEvent test facet.

Closes: https://github.com/square/okhttp/issues/5578
2019-12-30 13:11:17 -05:00
Jesse Wilson
d52e2d34d6 Convert RecordingEventListener to Kotlin 2019-12-29 20:40:02 -05:00
Jesse Wilson
96e596117e Use our test rule instead of the Maven Surefire listener
Closes: https://github.com/square/okhttp/issues/4894
2019-12-20 08:45:37 -10:00
Yuri Schimke
5201424da7 JDK 13 and Gradle 6 (#5561)
* JDK 13 and Gradle 6 RC 1

* Wrong JDK

* Passes test on JDK 13

* Fix

* Spotless upgrade

* Update gradle-wrapper.properties

* Gradle 6
2019-11-10 08:25:13 -05:00
Yuri Schimke
a128299fdb Flaky test improvements (#5577)
* Flaky test improvements

Keep the client event logging for flaky tests even when another listener is applied

* revert

* fix

* Keep logging
2019-10-27 16:15:43 -04:00
Yuri Schimke
dd292590d3 Corretto Test (#5545)
* Testing with Corretto

* CI config

* Cleanup

* Ignore same tests conscrypt fails on

* Test with external sites

* Revert
2019-10-25 21:37:51 -04:00
Jesse Wilson
5917d7a083 Add a way for MockWebServer to track truncated requests
It now tracks inbound requests that fail with an IOException.

Also add a fix for the bug where we'd send 'END OF STREAM' on a stream
that we'd previously canceled, which raced with the 'RST STREAM' and led
to flakiness.

Before we ship the new API in RecordedRequest we should go over the
other cases where inbound HTTP requests fail and make sure they
get reported through this channel.

Closes: https://github.com/square/okhttp/issues/5388
2019-10-05 21:50:00 -04:00
Jesse Wilson
aad8a1420d Name tasks only in TaskRunner (#5526)
* Name tasks only in TaskRunner

Naming queues seemed good initially, but the names are mostly
mutually-redundant with task names.

This PR reduces debug information when a queue is still busy
when the test completes. I have a fix for that in a follow-up
change.

* Update okhttp/src/main/java/okhttp3/internal/ws/RealWebSocket.kt

Co-Authored-By: Yuri Schimke <yuri@schimke.ee>
2019-10-02 22:38:24 -04:00
Jesse Wilson
9849ab8e3b Create OkHttpClient instances eagerly in tests
We used to do this lazily because OkHttpClient instances were
somewhat heavy: each standalone instance held its own
ExecutorService for the connection pool.

Now that we have TaskRunner each instance is much more
lightweight and the drawbacks of creating instances eagerly
is negligible.
2019-09-28 20:53:12 -04:00
Jesse Wilson
fe40324a4b TaskRunner support for shutting down queues
Shutting down queues makes it easier to implement HTTP/2
shutdown because we can enqueue everywhere and centralize
the logic that decides whether we're shutdown or not.

Use this new functionality to implement HTTP/2 on task queues.
It's mostly a drop-in replacement, though opting-into cancel
looks like a mistake when it's what we do most of the time.

When testing this the OkHttpClientTestRule was failing because
tasks were incomplete. I was puzzled by this until I realized
that the OkHttpClientTestRule performs that validation before
we stop the MockWebServer. I changed MockWebServer to have its
own TaskRunner and that made the problem go away.
2019-09-26 21:12:40 -04:00
Jesse Wilson
bc3ad111ad Adopt TaskRunner in RealConnectionPool
This also configures tests to assert that the connection pool
isn't doing any work after the test completes.
2019-09-26 08:16:50 -04:00
Yuri Schimke
7cf508a30b OpenJSSE Platform support (#5369)
Adds support for OpenJSSE when registered as the first security provider.
2019-08-18 12:03:51 +03:00
Yuri Schimke
1b60e3739c Test Android session reuse 2019-08-11 10:48:43 +01:00
Yuri Schimke
2a1f328d58 Add proxy event logging (#5300) 2019-07-25 05:42:32 +01:00
Yuri Schimke
2c7811a64a Move flaky issues to comments (#5289) 2019-07-16 22:50:51 +01:00
Yuri Schimke
a6c4ff6e44 Output client events after tagged @Flaky tests or failures (#5217)
Collect additional debugging info for know problem tests or after unplanned failures.
2019-07-16 22:34:32 +01:00
Yuri Schimke
16b7e36968 Fix for conscrypt tests (#5263) 2019-07-03 07:20:28 +01:00
Yuri Schimke
bdd6c3944f Testing with JDK 12 and latest 11.0.3 (#5212)
JDK 12 and be more specific about when we expect failures, e.g. 11.0.3 has fixes we should take into account.
2019-07-02 07:21:58 +01:00
Yuri Schimke
d81ec0f23b OkHttpClientTestRule check connectionCount instead of idle (#5226)
* OkHttpClientTestRule check connectionCount instead of idle

Clients should be clean after use, not just from idle connections.

* Abandon unclean clients

* Simplify logic
2019-06-25 22:34:51 -07:00
Jesse Wilson
ad5d6b8a7b Make OkHttpClientTestRule more powerful.
I'm hoping to follow this up with a change so that this rule can also do the
uncaught exception handling that we're currently doing elsewhere.

See https://github.com/square/okhttp/issues/4894
2019-06-15 22:08:18 -04:00
Amir Livneh
8deaef6702 Fix race condition in RecordingHostnameVerifier
When connections are established concurrently, verify() sometimes throws a `java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 0` because of unsynchronized access to the `calls` list.
2019-04-23 10:19:22 -07:00
Yuri Schimke
f3949c23bc Spotless code formatter 2019-04-10 22:44:58 +01:00
Yuri Schimke
9e12bc4d60 Improve PlatformRule autodetection (#4920)
Run more platforms in circleci.
Auto detect platform in IDE.
Surface more platform assumptions in tests.
2019-04-10 19:31:35 +01:00
TangHuaiZhe
a7603602ca add @overide for subclass override method 2019-03-30 12:46:18 +08:00
Jesse Wilson
dc1e870d24 Basic Gradle support 2019-03-17 00:16:26 -04:00
Jesse Wilson
dedc6ecd5b Use more AssertJ features 2019-03-14 17:57:42 -04:00
Jesse Wilson
695b46cb2e [maven-release-plugin] prepare for next development iteration 2019-03-13 23:42:40 -04:00
Jesse Wilson
44d51d0ceb [maven-release-plugin] prepare release parent-3.14.0 2019-03-13 23:42:33 -04:00
Benoît Quenaudon
6c4855a7c7 Use AssertJ in tests (#4713) 2019-03-13 21:07:33 -04:00
Amir Livneh
018510fa40 Rename OkHttpClientTestingRule to OkHttpClientTestRule 2019-03-07 07:24:05 -05:00