Skip to content

Commit

Permalink
[INDY-1001] Move plenum/test/instances tests to sdk (hyperledger#563)
Browse files Browse the repository at this point in the history
* Initial test change

Signed-off-by: ArtObr <[email protected]>

* Import fix

Signed-off-by: ArtObr <[email protected]>

* little fix

Signed-off-by: ArtObr <[email protected]>

* little import fix

Signed-off-by: ArtObr <[email protected]>

* Division imports from conftest to different folders

Signed-off-by: ArtObr <[email protected]>

* Fix for test pass

Signed-off-by: ArtObr <[email protected]>
  • Loading branch information
ArtObr authored and Andrew Nikitin committed Apr 10, 2018
1 parent 605d850 commit ff4c670
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
checkNodeRemotes
from plenum.test.test_stack import CONNECTED, JOINED_NOT_ALLOWED
from plenum.test import waits


whitelist = ['discarding message']
from plenum.test.pool_transactions.conftest import looper

logger = getlogger()

Expand Down Expand Up @@ -59,7 +57,7 @@ def addNodeBackAndCheck(nodeIdx: int, expectedStatus: Status):
addNodeBack(nodeSet, looper, nodeNames[nodeIdx])

timeout = waits.expectedNodeStartUpTimeout() + \
waits.expectedPoolInterconnectionTime(len(nodeSet))
waits.expectedPoolInterconnectionTime(len(nodeSet))
# TODO: Probably it's better to modify waits.* functions
timeout *= 1.5
looper.run(eventually(checkNodeStatusRemotesAndF,
Expand Down
15 changes: 9 additions & 6 deletions plenum/test/instances/test_msgs_from_slow_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,30 @@
from plenum.test.delayers import delayerMsgTuple
from plenum.test.test_node import TestNode
from plenum.test import waits

from plenum.test.pool_transactions.conftest import looper
from plenum.test.node_request.conftest import committed1, \
prepared1, preprepared1, propagated1, reqAcked1, \
sent1, noRetryReq, faultyNodes

nodeCount = 4

faultyNodes = 1


@pytest.fixture()
def configNodeSet(nodeSet):
A, B, C, D = nodeSet.nodes.values()
def configNodeSet(txnPoolNodeSet):
A, B, C, D = txnPoolNodeSet
# Nodes C and D delay Commit request from node A for protocol instance 0
for n in [C, D]:
n.nodeIbStasher.delay(delayerMsgTuple(30,
Commit,
senderFilter=A.name,
instFilter=0))
return nodeSet
return txnPoolNodeSet


def testMsgFromInstanceDelay(configNodeSet, looper, prepared1):
A, B, C, D = configNodeSet.nodes.values()
A, B, C, D = configNodeSet

def getCommits(node: TestNode, instId: int):
replica = node.replicas[instId] # type: Replica
Expand All @@ -41,6 +44,6 @@ def checkPresence():
assert len(commReqs) > 0
assert Replica.generateName(A.name, 1) in commReqs[0][0]

numOfNodes = len(configNodeSet.nodes)
numOfNodes = len(configNodeSet)
timeout = waits.expectedClientRequestPropagationTime(numOfNodes)
looper.run(eventually(checkPresence, retryWait=.5, timeout=timeout))
18 changes: 10 additions & 8 deletions plenum/test/instances/test_multiple_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
sendDuplicate3PhaseMsg
from plenum.test.test_node import getNonPrimaryReplicas, getPrimaryReplica
from plenum.test import waits

whitelist = [Suspicions.DUPLICATE_CM_SENT.reason,
'cannot process incoming COMMIT']
from plenum.test.pool_transactions.conftest import looper
from plenum.test.node_request.conftest import committed1, \
prepared1, preprepared1, propagated1, reqAcked1, \
sent1, noRetryReq, faultyNodes


@pytest.fixture("module")
def setup(nodeSet, up):
primaryRep, nonPrimaryReps = getPrimaryReplica(nodeSet, 0), \
getNonPrimaryReplicas(nodeSet, 0)
def setup(txnPoolNodeSet):
primaryRep, nonPrimaryReps = getPrimaryReplica(txnPoolNodeSet, 0), \
getNonPrimaryReplicas(txnPoolNodeSet, 0)

faultyRep = nonPrimaryReps[0]
makeNodeFaulty(faultyRep.node, partial(sendDuplicate3PhaseMsg,
Expand All @@ -32,13 +33,14 @@ def setup(nodeSet, up):
# want to check for a particular suspicion

whitelistNode(faultyRep.node.name,
[node for node in nodeSet if node != faultyRep.node],
[node for node in txnPoolNodeSet if node != faultyRep.node],
Suspicions.DUPLICATE_CM_SENT.code)

# If the request is ordered then COMMIT will be rejected much earlier
for r in [primaryRep, *nonPrimaryReps]:
def do_nothing(self, commit):
pass

r.doOrder = types.MethodType(do_nothing, r)

return adict(primaryRep=primaryRep, nonPrimaryReps=nonPrimaryReps,
Expand All @@ -53,7 +55,7 @@ def testMultipleCommit(setup, looper, sent1):
should count only one COMMIT from that sender
"""
primaryRep, nonPrimaryReps, faultyRep = setup.primaryRep, \
setup.nonPrimaryReps, setup.faultyRep
setup.nonPrimaryReps, setup.faultyRep

def chkSusp():
for r in (primaryRep, *nonPrimaryReps):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from plenum.test.spy_helpers import getAllArgs
from plenum.test import waits


nodeCount = 7


Expand Down
19 changes: 7 additions & 12 deletions plenum/test/instances/test_multiple_pre_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,16 @@
sendDuplicate3PhaseMsg
from plenum.test.test_node import getNonPrimaryReplicas, getPrimaryReplica
from plenum.test import waits


whitelist = [Suspicions.DUPLICATE_PPR_SENT.reason,
'cannot process incoming PRE-PREPARE',
Suspicions.UNKNOWN_PR_SENT.reason,
'Invalid prepare message received',
'cannot process incoming PREPARE',
Suspicions.UNKNOWN_CM_SENT.reason,
'cannot process incoming COMMIT']
from plenum.test.pool_transactions.conftest import looper
from plenum.test.node_request.conftest import committed1, \
prepared1, preprepared1, propagated1, reqAcked1, \
sent1, noRetryReq, faultyNodes


@pytest.fixture("module")
def setup(nodeSet, up):
primaryRep, nonPrimaryReps = getPrimaryReplica(nodeSet, 0), \
getNonPrimaryReplicas(nodeSet, 0)
def setup(txnPoolNodeSet):
primaryRep, nonPrimaryReps = getPrimaryReplica(txnPoolNodeSet, 0), \
getNonPrimaryReplicas(txnPoolNodeSet, 0)

# The primary replica would send 3 duplicate PRE-PREPARE requests to
# non primary replicas
Expand Down
18 changes: 9 additions & 9 deletions plenum/test/instances/test_multiple_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
sendDuplicate3PhaseMsg
from plenum.test.test_node import getNonPrimaryReplicas, getPrimaryReplica
from plenum.test import waits

whitelist = [Suspicions.DUPLICATE_PR_SENT.reason,
'Invalid prepare message received',
'cannot process incoming PREPARE']
from plenum.test.pool_transactions.conftest import looper
from plenum.test.node_request.conftest import committed1, \
prepared1, preprepared1, propagated1, reqAcked1, \
sent1, noRetryReq, faultyNodes


@pytest.fixture("module")
def setup(nodeSet, up):
primaryRep, nonPrimaryReps = getPrimaryReplica(nodeSet, 0), \
getNonPrimaryReplicas(nodeSet, 0)
def setup(txnPoolNodeSet):
primaryRep, nonPrimaryReps = getPrimaryReplica(txnPoolNodeSet, 0), \
getNonPrimaryReplicas(txnPoolNodeSet, 0)

# A non primary replica sends duplicate PREPARE requests to all other
# replicas
Expand All @@ -34,7 +34,7 @@ def setup(nodeSet, up):
# want to check for a particular suspicion

whitelistNode(faultyRep.node.name,
[node for node in nodeSet if node != faultyRep.node],
[node for node in txnPoolNodeSet if node != faultyRep.node],
Suspicions.DUPLICATE_PR_SENT.code)

return adict(primaryRep=primaryRep, nonPrimaryReps=nonPrimaryReps,
Expand All @@ -50,7 +50,7 @@ def testMultiplePrepare(setup, looper, sent1):
"""

primaryRep, nonPrimaryReps, faultyRep = setup.primaryRep, \
setup.nonPrimaryReps, setup.faultyRep
setup.nonPrimaryReps, setup.faultyRep

def chkSusp():
for r in (primaryRep, *nonPrimaryReps):
Expand Down
15 changes: 7 additions & 8 deletions plenum/test/instances/test_pre_prepare_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from stp_core.loop.eventually import eventually
from plenum.common.messages.node_messages import PrePrepare
from plenum.common.util import adict
from stp_core.common.util import adict
from plenum.server.suspicion_codes import Suspicions
from plenum.test.helper import getNodeSuspicions
Expand All @@ -13,16 +12,16 @@
send3PhaseMsgWithIncorrectDigest
from plenum.test.test_node import getNonPrimaryReplicas, getPrimaryReplica
from plenum.test import waits


whitelist = [Suspicions.PPR_DIGEST_WRONG.reason,
'cannot process incoming PRE-PREPARE']
from plenum.test.pool_transactions.conftest import looper
from plenum.test.node_request.conftest import committed1, \
prepared1, preprepared1, propagated1, reqAcked1, \
sent1, noRetryReq, faultyNodes


@pytest.fixture("module")
def setup(nodeSet, up):
primaryRep, nonPrimaryReps = getPrimaryReplica(nodeSet, 0), \
getNonPrimaryReplicas(nodeSet, 0)
def setup(txnPoolNodeSet):
primaryRep, nonPrimaryReps = getPrimaryReplica(txnPoolNodeSet, 0), \
getNonPrimaryReplicas(txnPoolNodeSet, 0)

# The primary replica would send PRE-PREPARE messages with incorrect digest
makeNodeFaulty(primaryRep.node, partial(send3PhaseMsgWithIncorrectDigest,
Expand Down
21 changes: 9 additions & 12 deletions plenum/test/instances/test_prepare_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@
send3PhaseMsgWithIncorrectDigest
from plenum.test.test_node import getNonPrimaryReplicas, getPrimaryReplica
from plenum.test import waits


whitelist = [Suspicions.PR_DIGEST_WRONG.reason,
'Invalid prepare message received',
'cannot process incoming PREPARE',
Suspicions.CM_DIGEST_WRONG.reason,
'cannot process incoming COMMIT']
from plenum.test.pool_transactions.conftest import looper
from plenum.test.node_request.conftest import committed1, \
prepared1, preprepared1, propagated1, reqAcked1, \
sent1, noRetryReq, faultyNodes


@pytest.fixture("module")
def setup(nodeSet, up):
primaryRep, nonPrimaryReps = getPrimaryReplica(nodeSet, 0), \
getNonPrimaryReplicas(nodeSet, 0)
def setup(txnPoolNodeSet):
primaryRep, nonPrimaryReps = getPrimaryReplica(txnPoolNodeSet, 0), \
getNonPrimaryReplicas(txnPoolNodeSet, 0)

# A non primary replica sends PREPARE messages with incorrect digest

Expand All @@ -44,8 +41,8 @@ def testPrepareDigest(setup, looper, sent1):
"""

primaryRep, nonPrimaryReps, faultyRep = setup.primaryRep, \
setup.nonPrimaryReps, \
setup.faultyRep
setup.nonPrimaryReps, \
setup.faultyRep

def chkSusp():
for r in (primaryRep, *nonPrimaryReps):
Expand Down

0 comments on commit ff4c670

Please sign in to comment.