Skip to content

Commit b3b5e7a

Browse files
committed
test(simulation): Fix flaky test test_many_miners_since_beginning
1 parent e305645 commit b3b5e7a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

hathor/simulator/fake_connection.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,42 +71,50 @@ def disable_idle_timeout(self):
7171
self._proto1.disable_idle_timeout()
7272
self._proto2.disable_idle_timeout()
7373

74-
def is_both_synced(self) -> bool:
74+
def is_both_synced(self, *, errmsgs: Optional[list[str]] = None) -> bool:
7575
"""Short-hand check that can be used to make "step loops" without having to guess the number of iterations."""
76+
if errmsgs is None:
77+
errmsgs = []
7678
from hathor.p2p.states.ready import ReadyState
7779
conn1_aborting = self._proto1.aborting
7880
conn2_aborting = self._proto2.aborting
7981
if conn1_aborting or conn2_aborting:
8082
self.log.debug('conn aborting', conn1_aborting=conn1_aborting, conn2_aborting=conn2_aborting)
83+
errmsgs.append('conn aborting')
8184
return False
8285
state1 = self._proto1.state
8386
state2 = self._proto2.state
8487
state1_is_ready = isinstance(state1, ReadyState)
8588
state2_is_ready = isinstance(state2, ReadyState)
8689
if not state1_is_ready or not state2_is_ready:
8790
self.log.debug('peer not ready', peer1_ready=state1_is_ready, peer2_ready=state2_is_ready)
91+
errmsgs.append('peer not ready')
8892
return False
8993
assert isinstance(state1, ReadyState) # mypy can't infer this from the above
9094
assert isinstance(state2, ReadyState) # mypy can't infer this from the above
9195
state1_is_errored = state1.sync_agent.is_errored()
9296
state2_is_errored = state2.sync_agent.is_errored()
9397
if state1_is_errored or state2_is_errored:
9498
self.log.debug('peer errored', peer1_errored=state1_is_errored, peer2_errored=state2_is_errored)
99+
errmsgs.append('peer errored')
95100
return False
96101
state1_is_synced = state1.sync_agent.is_synced()
97102
state2_is_synced = state2.sync_agent.is_synced()
98103
if not state1_is_synced or not state2_is_synced:
99104
self.log.debug('peer not synced', peer1_synced=state1_is_synced, peer2_synced=state2_is_synced)
105+
errmsgs.append('peer not synced')
100106
return False
101107
[best_block_info1] = state1.protocol.node.tx_storage.get_n_height_tips(1)
102108
[best_block_info2] = state2.protocol.node.tx_storage.get_n_height_tips(1)
103109
if best_block_info1.id != best_block_info2.id:
104110
self.log.debug('best block is different')
111+
errmsgs.append('best block is different')
105112
return False
106113
tips1 = {i.data for i in state1.protocol.node.tx_storage.get_tx_tips()}
107114
tips2 = {i.data for i in state2.protocol.node.tx_storage.get_tx_tips()}
108115
if tips1 != tips2:
109116
self.log.debug('tx tips are different')
117+
errmsgs.append('tx tips are different')
110118
return False
111119
return True
112120

tests/simulation/test_simulator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_many_miners_since_beginning(self):
8787
for miner in miners:
8888
miner.stop()
8989

90-
self.assertTrue(self.simulator.run(3600, trigger=AllTriggers(stop_triggers)))
90+
self.simulator.run(3600, trigger=AllTriggers(stop_triggers))
9191

9292
for node in nodes[1:]:
9393
self.assertTipsEqual(nodes[0], node)

0 commit comments

Comments
 (0)