-
-
Notifications
You must be signed in to change notification settings - Fork 316
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
chore: fix flaky test when leader peer terminates #981
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit should fix a flaky test that happens when the leadership changes because the previous leader terminates for a given reason. The issue happens because the signal emitted in the unit test is a `GenServer.stop/1`, but the peer process is under the test supervisor, so, in certain circumstances, the supervisor is fast enough to spawn a new process. That process ends as the new leader. A way to reproduce the flaky test locally could be like this: ```console for i in (seq 1 10) mix test --seed 856757 if test $status -eq 2 break end end ``` I'm using the fish shell here; the previous script might not work on your favorite shell. The previous command should produce an output like: ```console Excluding tags: [:skip] ................................................................................................................................................................................................................................................................................................................... Finished in 4.2 seconds (1.4s async, 2.7s sync) 24 doctests, 7 properties, 278 tests, 0 failures, 2 excluded Randomized with seed 856757 Excluding tags: [:skip] ................................................................................................................................................................................................................................................................................................ 1) test leadership changes when a peer terminates (Oban.Peers.GlobalTest) test/oban/peers/global_test.exs:24 Expected truthy, got nil code: assert Enum.find([peer_1, peer_2] -- [leader], &Global.leader?/1) arguments: # 1 [#PID<0.3478.0>] # 2 &Oban.Peers.Global.leader?/1 stacktrace: test/oban/peers/global_test.exs:44: anonymous fn/3 in Oban.Peers.GlobalTest."test leadership changes when a peer terminates"/1 (oban 2.16.3) test/support/case.ex:73: Oban.Case.with_backoff/4 test/oban/peers/global_test.exs:43: (test) .................. Finished in 5.3 seconds (1.4s async, 3.8s sync) 24 doctests, 7 properties, 278 tests, 1 failure, 2 excluded Randomized with seed 856757 ``` Here, you can see that the PID of the new leader is not in the target list (`Enum.find`), so, as I mentioned before, one theory is that the test supervisor spawned a new process, and that process ended being the leader.
milmazz
force-pushed
the
chore/fix-flaky-test
branch
from
October 31, 2023 14:08
10feb3f
to
9bdf8e2
Compare
sorentwo
approved these changes
Oct 31, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fantastic! Thanks for tracking this down 👏
sorentwo
pushed a commit
that referenced
this pull request
Nov 3, 2023
This commit should fix a flaky test that happens when the leadership changes because the previous leader terminates for a given reason. The issue happens because the signal emitted in the unit test is a `GenServer.stop/1`, but the peer process is under the test supervisor, so, in certain circumstances, the supervisor is fast enough to spawn a new process. That process ends as the new leader. A way to reproduce the flaky test locally could be like this: ```console for i in (seq 1 10) mix test --seed 856757 if test $status -eq 2 break end end ``` I'm using the fish shell here; the previous script might not work on your favorite shell. The previous command should produce an output like: ```console Excluding tags: [:skip] ................................................................................................................................................................................................................................................................................................................... Finished in 4.2 seconds (1.4s async, 2.7s sync) 24 doctests, 7 properties, 278 tests, 0 failures, 2 excluded Randomized with seed 856757 Excluding tags: [:skip] ................................................................................................................................................................................................................................................................................................ 1) test leadership changes when a peer terminates (Oban.Peers.GlobalTest) test/oban/peers/global_test.exs:24 Expected truthy, got nil code: assert Enum.find([peer_1, peer_2] -- [leader], &Global.leader?/1) arguments: # 1 [#PID<0.3478.0>] # 2 &Oban.Peers.Global.leader?/1 stacktrace: test/oban/peers/global_test.exs:44: anonymous fn/3 in Oban.Peers.GlobalTest."test leadership changes when a peer terminates"/1 (oban 2.16.3) test/support/case.ex:73: Oban.Case.with_backoff/4 test/oban/peers/global_test.exs:43: (test) .................. Finished in 5.3 seconds (1.4s async, 3.8s sync) 24 doctests, 7 properties, 278 tests, 1 failure, 2 excluded Randomized with seed 856757 ``` Here, you can see that the PID of the new leader is not in the target list (`Enum.find`), so, as I mentioned before, one theory is that the test supervisor spawned a new process, and that process ended being the leader.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit should fix a flaky test that happens when the leadership changes because the previous leader terminates for a given reason.
The issue happens because the signal emitted in the unit test is a
GenServer.stop/1
, but the peer process is under the test supervisor, so, in certain circumstances, the supervisor is fast enough to spawn a new process. That process ends as the new leader.A way to reproduce the flaky test locally could be like this:
I'm using the fish shell here; the previous script might not work on your favorite shell.
The previous command should produce an output like:
Here, you can see that the PID of the new leader is not in the target list (
Enum.find
), so, as I mentioned before, one theory is that the test supervisor spawned a new process, and that process ended being the leader.