Skip to content

INDY-2223: Improve simulation tests #1333

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

Merged
merged 6 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def test_view_change_while_ordering_with_real_msgs(seed):
partial(node._view_changer.process_need_view_change, NeedViewChange(view_no=1)))
# 3. Make sure that view_change is completed
for node in pool.nodes:
pool.timer.wait_for(lambda: node._view_changer._data.view_no == 1, timeout=20000)
pool.timer.wait_for(lambda: node._view_changer._data.view_no == 1)

# 3. Make sure all nodes ordered all the requests
for node in pool.nodes:
pool.timer.wait_for(partial(check_batch_count, node, batches_count), timeout=20000)
pool.timer.wait_for(partial(check_batch_count, node, batches_count))

# 4. Check data consistency
check_consistency(pool)
4 changes: 1 addition & 3 deletions plenum/test/consensus/view_change/test_sim_view_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def calc_committed(view_changes):
return committed


# Increased count from 200 to 150 because of jenkin's failures.
# After integration, need to get it back
@pytest.mark.parametrize("seed", range(150))
@pytest.mark.parametrize("seed", range(200))
def test_view_change_completes_under_normal_conditions(seed):
random = DefaultSimRandom(seed)
check_view_change_completes_under_normal_conditions(random)
Expand Down
13 changes: 9 additions & 4 deletions plenum/test/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,19 +1402,24 @@ def run_for(self, seconds):
"""
self.advance_until(self._ts.value + seconds)

def wait_for(self, condition: Callable[[], bool], timeout: Optional = None):
def wait_for(self, condition: Callable[[], bool], timeout: Optional = None, max_iterations: int = 500000):
"""
Advance time in steps until condition is reached, running scheduled callbacks in process
Throws TimeoutError if fail to reach condition (under required timeout if defined)
"""
counter = 0
deadline = self._ts.value + timeout if timeout else None
while self._events and not condition():
while self._events and not condition() and counter < max_iterations:
if deadline and self._next_timestamp() > deadline:
raise TimeoutError("Failed to reach condition in required time")
raise TimeoutError("Failed to reach condition in required time, {} iterations passed".format(counter))
self.advance()
counter += 1

if not condition():
raise TimeoutError("Condition will be never reached")
if not self._events:
raise TimeoutError("Condition will be never reached, {} iterations passed".format(counter))
else:
raise TimeoutError("Failed to reach condition in {} iterations".format(max_iterations))

def run_to_completion(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion plenum/test/simulation/sim_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _send_message(self, frm: str, msg: Any, dst: ExternalBus.Destination):
else:
assert False, "{} tried to send message {} to unsupported destination {}".format(frm, msg, dst)

for name in dst:
for name in sorted(dst):
assert name != frm, "{} tried to send message {} to itself".format(frm, msg)

peer = self._peers.get(name)
Expand Down