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

Fix potential flaky test #1350

Merged
merged 1 commit into from
Feb 5, 2021
Merged

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Feb 4, 2021

When starting webrick in-process in a background thread WITH a fixed port, we need to make sure that the webrick thread has shut down between tests, otherwise a follow-up test can fail with

Errno::EADDRINUSE: Address already in use - bind(2) for [::]:6218

due to the main test runner thread being faster at starting the next test case before the old webrick thread has had time to shut down.

In this specific case, there's only a single test case for this file, so this issue would only trigger whenever another test case also uses webrick with a fixed port OR once more test cases are added to this file.

I ran into this because there's a test in the profiling branch that was partially copy-pasted from this one and had exactly the same issue, so I'm fixing the issue on both places.

Tips for hunting down these kinds of issues:

  • The rspec_n gem (thanks @roberts1000 !) was very useful in running a given test case multiple times to cause it to trigger
  • This specific issue can be triggered really easily by modifying the webrick sources and adding a sleep 1 to the webrick shutdown sequence, thus making sure the background thread always gets delayed

When starting webrick in-process in a background thread WITH a fixed
port, we need to make sure that the webrick thread has shut down
between tests, otherwise a follow-up test can fail with

`Errno::EADDRINUSE: Address already in use - bind(2) for [::]:6218`

due to the main test runner thread being faster at starting the next
test case before the old webrick thread has had time to shut down.

In this specific case, there's only a single test case for this file,
so this issue would only trigger whenever another test case also uses
webrick with a fixed port OR once more test cases are added to this
file.

I ran into this because there's a test in the profiling branch that
was partially copy-pasted from this one and had exactly the same issue,
so I'm fixing the issue on both places.

Tips for hunting down these kinds of issues:
* The `rspec_n` (thanks @roberts1000 !) was very useful in running
  a given test case multiple times to cause it to trigger
* This specific issue can be triggered really easily by modifying the
  webrick sources and adding a `sleep 1` to the webrick shutdown
  sequence, thus making sure the background thread always gets delayed
@ivoanjo ivoanjo requested a review from a team February 4, 2021 15:04
ivoanjo added a commit that referenced this pull request Feb 4, 2021
When starting webrick in-process in a background thread WITH a fixed
port, we need to make sure that the webrick thread has shut down
between tests, otherwise a follow-up test can fail with

`Errno::EADDRINUSE: Address already in use - bind(2) for [::]:6218`

due to the main test runner thread being faster at starting the next
test case before the old webrick thread has had time to shut down.

This is the same issue as fixed in #1350 (both tests are similar).

Tips for hunting down these kinds of issues:
* The `rspec_n` (thanks @roberts1000 !) was very useful in running
  a given test case multiple times to cause it to trigger
* This specific issue can be triggered really easily by modifying the
  webrick sources and adding a `sleep 1` to the webrick shutdown
  sequence, thus making sure the background thread always gets delayed
@ivoanjo
Copy link
Member Author

ivoanjo commented Feb 5, 2021

The broken test on JRuby is unrelated and was fixed on #1353 . Merging.

@ivoanjo ivoanjo merged commit 9ee8fc7 into master Feb 5, 2021
@ivoanjo ivoanjo deleted the ivoanjo/fix-potential-flaky-test branch February 5, 2021 08:57
@github-actions github-actions bot added this to the 0.46.0 milestone Feb 5, 2021
ivoanjo added a commit that referenced this pull request Feb 9, 2021
When starting webrick in-process in a background thread WITH a fixed
port, we need to make sure that the webrick thread has shut down
between tests, otherwise a follow-up test can fail with

`Errno::EADDRINUSE: Address already in use - bind(2) for [::]:6218`

due to the main test runner thread being faster at starting the next
test case before the old webrick thread has had time to shut down.

This is the same issue as fixed in #1350 (both tests are similar).

Tips for hunting down these kinds of issues:
* The `rspec_n` (thanks @roberts1000 !) was very useful in running
  a given test case multiple times to cause it to trigger
* This specific issue can be triggered really easily by modifying the
  webrick sources and adding a `sleep 1` to the webrick shutdown
  sequence, thus making sure the background thread always gets delayed
ivoanjo added a commit that referenced this pull request Mar 11, 2021
When starting webrick in-process in a background thread WITH a fixed
port, we need to make sure that the webrick thread has shut down
between tests, otherwise a follow-up test can fail with

`Errno::EADDRINUSE: Address already in use - bind(2) for [::]:6218`

due to the main test runner thread being faster at starting the next
test case before the old webrick thread has had time to shut down.

This is the same issue as fixed in #1350 (both tests are similar).

Tips for hunting down these kinds of issues:
* The `rspec_n` (thanks @roberts1000 !) was very useful in running
  a given test case multiple times to cause it to trigger
* This specific issue can be triggered really easily by modifying the
  webrick sources and adding a `sleep 1` to the webrick shutdown
  sequence, thus making sure the background thread always gets delayed
ivoanjo added a commit that referenced this pull request Mar 16, 2021
When starting webrick in-process in a background thread WITH a fixed
port, we need to make sure that the webrick thread has shut down
between tests, otherwise a follow-up test can fail with

`Errno::EADDRINUSE: Address already in use - bind(2) for [::]:6218`

due to the main test runner thread being faster at starting the next
test case before the old webrick thread has had time to shut down.

This is the same issue as fixed in #1350 (both tests are similar).

Tips for hunting down these kinds of issues:
* The `rspec_n` (thanks @roberts1000 !) was very useful in running
  a given test case multiple times to cause it to trigger
* This specific issue can be triggered really easily by modifying the
  webrick sources and adding a `sleep 1` to the webrick shutdown
  sequence, thus making sure the background thread always gets delayed
ivoanjo added a commit that referenced this pull request Mar 29, 2021
When starting webrick in-process in a background thread WITH a fixed
port, we need to make sure that the webrick thread has shut down
between tests, otherwise a follow-up test can fail with

`Errno::EADDRINUSE: Address already in use - bind(2) for [::]:6218`

due to the main test runner thread being faster at starting the next
test case before the old webrick thread has had time to shut down.

This is the same issue as fixed in #1350 (both tests are similar).

Tips for hunting down these kinds of issues:
* The `rspec_n` (thanks @roberts1000 !) was very useful in running
  a given test case multiple times to cause it to trigger
* This specific issue can be triggered really easily by modifying the
  webrick sources and adding a `sleep 1` to the webrick shutdown
  sequence, thus making sure the background thread always gets delayed
ivoanjo added a commit that referenced this pull request Apr 12, 2021
When starting webrick in-process in a background thread WITH a fixed
port, we need to make sure that the webrick thread has shut down
between tests, otherwise a follow-up test can fail with

`Errno::EADDRINUSE: Address already in use - bind(2) for [::]:6218`

due to the main test runner thread being faster at starting the next
test case before the old webrick thread has had time to shut down.

This is the same issue as fixed in #1350 (both tests are similar).

Tips for hunting down these kinds of issues:
* The `rspec_n` (thanks @roberts1000 !) was very useful in running
  a given test case multiple times to cause it to trigger
* This specific issue can be triggered really easily by modifying the
  webrick sources and adding a `sleep 1` to the webrick shutdown
  sequence, thus making sure the background thread always gets delayed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants