update test_view_change_timeout
@@ -13,7 +13,7 @@ from plenum.test.test_node import getPrimaryReplica, get_master_primary_node, \
ensureElectionsDone, checkProtocolInstanceSetup
from plenum.test.test_node import getPrimaryReplica, ensureElectionsDone
from plenum.test.delayers import icDelay
-
+from plenum.test.view_change.helper import ensure_view_change
nodeCount = 7
@@ -94,15 +94,49 @@ def testViewChangeCase1(nodeSet, looper, up, wallet1, client1, viewNo):
def test_view_change_timeout(nodeSet, looper, up, wallet1, client1, viewNo):
+ """
+ Check view change restarted if it is not completed in time
+ """
+
+ m_primary_node = get_master_primary_node(list(nodeSet.nodes.values()))
+
+ # Setting view change timeout to low value to make test pass quicker
for node in nodeSet:
node._primary_election_timeout = 5
- delayNonPrimaries(nodeSet, 0, 10)
+
+ # Delaying view change messages to make first view change fail
+ # due to timeout
for node in nodeSet:
node.nodeIbStasher.delay(icDelay(delay=5))
+
+ # Delaying preprepae messages from nodes and
+ # sending request to force view change
+ for i in range(3):
+ delayNonPrimaries(nodeSet, instId=i, delay=10)
sendReqsToNodesAndVerifySuffReplies(looper, wallet1, client1, 4)
- waitForViewChange(looper, nodeSet)
+
+ # First view change should fail, because of delayed
+ # instance change messages.
+ # This then leads to new view change that we need.
+ try:
+ ensure_view_change(looper, nodeSet)
+ ensureElectionsDone(looper=looper, nodes=nodeSet)
+ except AssertionError:
+ pass
+
+ # Resetting delays to let second view change go well
+ reset_delays_and_process_delayeds(nodeSet)
+
+ # This view change should be completed with no problems
+ ensure_view_change(looper, nodeSet)
+ ensureElectionsDone(looper=looper, nodes=nodeSet)
+
+ new_m_primary_node = get_master_primary_node(list(nodeSet.nodes.values()))
+ assert m_primary_node.name != new_m_primary_node.name
for node in nodeSet:
assert node.spylog.count('_check_view_change_completed') > 0
+ for node in nodeSet:
+ assert node.viewNo == (viewNo + 2)
def test_node_notified_about_primary_election_result(nodeSet, looper, up, wallet1, client1, viewNo):
