Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URLConnectionTest.testServerClosesOutput is flaky #4140

Closed
swankjesse opened this issue Jul 11, 2018 · 1 comment · Fixed by #4469
Closed

URLConnectionTest.testServerClosesOutput is flaky #4140

swankjesse opened this issue Jul 11, 2018 · 1 comment · Fixed by #4469
Labels
tests Fix relates to tests not code
Milestone

Comments

@swankjesse
Copy link
Collaborator

[ERROR] serverShutdownOutput(okhttp3.URLConnectionTest)  Time elapsed: 0.511 s  <<< FAILURE!
java.lang.AssertionError: expected:<0> but was:<1>
	at okhttp3.URLConnectionTest.testServerClosesOutput(URLConnectionTest.java:477)
	at okhttp3.URLConnectionTest.serverShutdownOutput(URLConnectionTest.java:434)
@swankjesse swankjesse added the tests Fix relates to tests not code label Jul 11, 2018
@swankjesse swankjesse added this to the 3.13 milestone Nov 4, 2018
@amirlivneh
Copy link
Collaborator

There are usually 2 requests sent to '/b' during the test:
#1 on the busted connection, attempting reuse
#2 on a new connection

On successful runs, the server records #1 and then #2 and adds them to the queue in that order.

On failed runs, the server starts reading request #1 before #2, but there is a context switch, and it finishes reading #2 before #1, recording them in that order. Since #1 is the last to be recorded, the test incorrectly uses it to assert that the sequence number is 0. Since #1 was the second to be received on the busted connection, it has a sequence number of 1 so the test fails.

A simple fix is to assert that either #1 or #2 has a sequence number of 0. I wonder if there is a cleaner way to assert that a new connection was used.

amirlivneh added a commit to amirlivneh/okhttp that referenced this issue Dec 25, 2018
There are usually 2 requests sent to '/b' during the test:
square#1 on the busted connection, attempting reuse
square#2 on a new connection

On successful runs, the server recorded square#1 and then square#2 and added them to the queue in that order.

On failed runs, the server started reading request square#1 before square#2, but there was a context switch, and it finished reading square#2 before square#1, recording them in that order. Since square#1 was the last to be recorded, the test incorrectly used it to assert that the sequence number is 0. Since square#1 was the second to be received on the busted connection, it had a sequence number of 1 so the test failed.

The fix removes the assumption that square#2 is the last to be recorded.

Fixes square#4140.
amirlivneh added a commit to amirlivneh/okhttp that referenced this issue Dec 25, 2018
There are usually 2 requests sent to '/b' during the test:
square#1 on the busted connection, attempting reuse
square#2 on a new connection

On successful runs, the server recorded square#1 and then square#2 and added them to the queue in that order.

On failed runs, the server started reading request square#1 before square#2, but there was a context switch, and it finished reading square#2 before square#1, recording them in that order. Since square#1 was the last to be recorded, the test incorrectly used it to assert that the sequence number was 0. Since square#1 was the second to be received on the busted connection, it had a sequence number of 1 so the test failed.

The fix removes the assumption that square#2 is the last to be recorded.

Fixes square#4140.
@swankjesse swankjesse modified the milestones: Backlog, 3.13 Feb 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Fix relates to tests not code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants