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

test(simulation): Fix flaky test test_many_miners_since_beginning #815

Merged
merged 1 commit into from
Oct 18, 2023

Conversation

msbrogli
Copy link
Member

@msbrogli msbrogli commented Oct 17, 2023

Background

The following tests were too flaky:

  • tests/simulation/test_simulator.py::SyncV1RandomSimulatorTestCase::test_many_miners_since_beginning
  • tests/simulation/test_simulator.py::SyncV2RandomSimulatorTestCase::test_many_miners_since_beginning
  • tests/simulation/test_simulator.py::SyncBridgeRandomSimulatorTestCase::test_many_miners_since_beginning

This PR does not fix the HeightIndex behavior. It just fixes the test itself.

Before this fix, one of these tests were failing every 3 executions. After this fix, I could locally run each of the three tests more than 50 times with only one failure coming from some other edge case. For clarity, 1 fail out of 150+ executions.

The only fail I got happened with seed 4231149425068099915. Here is the log: FAILED tests/simulation/test_simulator.py::SyncV2RandomSimulatorTestCase::test_many_miners_since_beginning - twisted.trial.unittest.FailTest: Items in the first set but not the second:.

Root cause analysis

The self.assertTrue(self.simulator.run(3600, trigger=AllTriggers(stop_triggers))) was failing. In other words, the run(...) method was returning False.

Why?

Because the AllTriggers(stop_triggers)) was not stopping the execution.

Why?

Because the StopWhenSynced trigger was using the tx_storage.get_n_height_tips() which was returning different block hashes for the nodes.

Why?

Because there's an edge case where all blockchains had exactly the same size and the same score (i.e., a tie between all blockchains). In this case, the HeightIndex does not update at all and keep returning the previous best blockchain, which is different for each full node. As get_n_height_tips() method uses the HeightIndex, the block hashes were different.

Acceptance Criteria

  1. Add some debugging tool to hathor.simulator.FakeConnection.is_both_synced().
  2. Remove assertTrue(...) in self.assertTrue(self.simulator.run(3600, trigger=AllTriggers(stop_triggers))).

Checklist

  • If you are requesting a merge into master, confirm this code is production-ready and can be included in future releases as soon as it gets merged

@msbrogli msbrogli requested a review from jansegre as a code owner October 17, 2023 22:52
@msbrogli msbrogli requested a review from glevco October 17, 2023 23:02
@msbrogli msbrogli self-assigned this Oct 17, 2023
@msbrogli msbrogli added the tests label Oct 17, 2023
glevco
glevco previously approved these changes Oct 17, 2023
jansegre
jansegre previously approved these changes Oct 18, 2023
tests/simulation/test_simulator.py Show resolved Hide resolved
@msbrogli msbrogli force-pushed the test/fix-flaky-test_many_miners_since_beginning branch from b3b5e7a to 96167d7 Compare October 18, 2023 15:31
@msbrogli msbrogli dismissed stale reviews from glevco and jansegre via 6b039c1 October 18, 2023 15:33
@msbrogli msbrogli force-pushed the test/fix-flaky-test_many_miners_since_beginning branch from 96167d7 to 6b039c1 Compare October 18, 2023 15:33
@msbrogli msbrogli merged commit 6b039c1 into master Oct 18, 2023
2 of 8 checks passed
@msbrogli msbrogli deleted the test/fix-flaky-test_many_miners_since_beginning branch October 18, 2023 15:36
@jansegre jansegre mentioned this pull request Nov 13, 2023
2 tasks
This was referenced Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants