From c65a14f8f9d122d54df1a380eb839bbd5a18d469 Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Fri, 15 Jan 2021 06:38:50 -0800 Subject: [PATCH] Add retry and timeout in unit test Signed-off-by: Ian Costanzo --- .../view_change/test_sim_view_change.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/plenum/test/consensus/view_change/test_sim_view_change.py b/plenum/test/consensus/view_change/test_sim_view_change.py index 0511da560b..67f036fe42 100644 --- a/plenum/test/consensus/view_change/test_sim_view_change.py +++ b/plenum/test/consensus/view_change/test_sim_view_change.py @@ -1,6 +1,8 @@ from collections import Counter from functools import partial +import time + import pytest from plenum.common.messages.internal_messages import NeedViewChange @@ -38,7 +40,7 @@ def test_view_change_completes_under_normal_conditions_regression_seeds(seed, la check_view_change_completes_under_normal_conditions(random, *latency, *filter) -def test_view_change_permutations(random): +def test_view_change_permutations(random: SimRandom): # Create pool in some random initial state pool, _ = some_pool(random) quorums = pool.nodes[0]._data.quorums @@ -62,7 +64,7 @@ def test_view_change_permutations(random): assert len(cps) == 1 # ToDo: this test fails on seeds {440868, 925547, 444939} -def test_new_view_combinations(random): +def test_new_view_combinations(random: SimRandom): # Create pool in some random initial state pool, _ = some_pool(random) quorums = pool.nodes[0]._data.quorums @@ -77,10 +79,16 @@ def test_new_view_combinations(random): # Check that all committed requests are present in final batches for _ in range(10): - num_votes = quorums.strong.value - votes = random.sample(view_change_messages, num_votes) - - cp = pool.nodes[0]._view_changer._new_view_builder.calc_checkpoint(votes) + cp = None + j = 0 + while j < 20 and not cp: + num_votes = quorums.strong.value + votes = random.sample(view_change_messages, num_votes) + + cp = pool.nodes[0]._view_changer._new_view_builder.calc_checkpoint(votes) + if not cp: + j = j + 1 + time.sleep(0.5) assert cp is not None batches = pool.nodes[0]._view_changer._new_view_builder.calc_batches(cp, votes)