test(simulation): Fix flaky test test_many_miners_since_beginning #815
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.
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, therun(...)
method was returningFalse
.Why?
Because the
AllTriggers(stop_triggers))
was not stopping the execution.Why?
Because the
StopWhenSynced
trigger was using thetx_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. Asget_n_height_tips()
method uses theHeightIndex
, the block hashes were different.Acceptance Criteria
hathor.simulator.FakeConnection.is_both_synced()
.assertTrue(...)
inself.assertTrue(self.simulator.run(3600, trigger=AllTriggers(stop_triggers)))
.Checklist
master
, confirm this code is production-ready and can be included in future releases as soon as it gets merged