summaryrefslogtreecommitdiff
path: root/annotations/generate_annotated_java_files.py
diff options
context:
space:
mode:
authorTobias Thierer <tobiast@google.com>2019-04-05 21:57:33 +0100
committerTobias Thierer <tobiast@google.com>2019-04-08 18:58:50 +0100
commit16bee58eee4f4f167defe54533baad54de3d337e (patch)
tree6c2b7564fc0621f79ec08f59daa551183312bfae /annotations/generate_annotated_java_files.py
parent24ac60ad50fd9b984dd5de68c64c2acc9ee0823a (diff)
HttpURLConnection: Add test coverage for concurrent disconnect.
HttpURLConnection is not thread safe, but some clients assume that they can disconnect() the connection from another thread and that this quickly unblocks the thread that is blocked reading. While we don't guarantee that this will always work, we do make a best effort. Existing tests (com.squareup.okhttp.internal.http.DisconnectTest, libcore.java.net.URLConnectionTest) only test disconnecting from the main thread. This CL adds coverage to test some common scenarios of the connection being disconnected from a background thread while the main thread is blocked (a) waiting to start reading the response headers, (b) waiting to start reading the response body, (c) part-way through reading the response body. Each test case spawns a background thread that calls disconnect() after 2 second; the test asserts that the reading thread encounters the expected IOException after roughly that amount of time (between 1 and 4 seconds). To guard confirm that the test is set up correctly, the test also checks what part of the response has been read by that time. We currently make no attempt to make it safe to also close() the InputStream from a background thread, so this is not tested. Fixes: 129771436 Test: atest CtsLibcoreTestCases:libcore.java.net.URLConnectionTest Test: Checked that all three added tests pass reliably (ran 500x each) on a Pixel 2 device even when all time margins are 1/10th of what they are in this CL. At 1/20th the durations / margins, running the tests 500x gets quite flaky. Change-Id: I1a848021b661b8675f57761cb30cbbe3da075aa7
Diffstat (limited to 'annotations/generate_annotated_java_files.py')
0 files changed, 0 insertions, 0 deletions