本文整理汇总了Python中stp_core.loop.eventually.eventually函数的典型用法代码示例。如果您正苦于以下问题:Python eventually函数的具体用法?Python eventually怎么用?Python eventually使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了eventually函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_propagate_of_ordered_request_doesnt_stash_requests_in_authenticator
def test_propagate_of_ordered_request_doesnt_stash_requests_in_authenticator(
looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client):
# Universal delayer
def stopAll(msg):
return 100000
def check_verified_req_list_is_empty():
for node in txnPoolNodeSet:
assert len(node.clientAuthNr._verified_reqs) == 0
# Order one request while cutting off last node
lastNode = txnPoolNodeSet[-1]
with delay_rules(lastNode.nodeIbStasher, stopAll), \
delay_rules(lastNode.clientIbStasher, stopAll):
sdk_send_random_and_check(looper, txnPoolNodeSet,
sdk_pool_handle,
sdk_wallet_client, 1)
old_propagates = [n.spylog.count('processPropagate') for n in txnPoolNodeSet]
def check_more_propagates_delivered():
new_propagates = [n.spylog.count('processPropagate') for n in txnPoolNodeSet]
assert all(old < new for old, new in zip(old_propagates, new_propagates))
# Wait until more propagates are delivered to all nodes
looper.run(eventually(check_more_propagates_delivered))
# Make sure that verified req list will be empty eventually
looper.run(eventually(check_verified_req_list_is_empty))
示例2: test_zstack_non_utf8
def test_zstack_non_utf8(tdir, looper, tconf):
"""
ZStack gets a non utf-8 message and does not hand it over to the
processing method
:return:
"""
names = ['Alpha', 'Beta']
genKeys(tdir, names)
(alpha, beta), (alphaP, betaP) = create_and_prep_stacks(names, tdir,
looper, tconf)
# Send a utf-8 message and see its received
for uid in alpha.remotes:
alpha.transmit(b'{"k1": "v1"}', uid, serialized=True)
looper.run(eventually(chkPrinted, betaP, {"k1": "v1"}))
# Send a non utf-8 message and see its not received (by the receiver method)
for uid in alpha.remotes:
alpha.transmit(b'{"k2": "v2\x9c"}', uid, serialized=True)
with pytest.raises(AssertionError):
looper.run(eventually(chkPrinted, betaP, {"k2": "v2\x9c"}))
# TODO: A better test where the output of the parsing method is checked
# requires spyable methods
# Again send a utf-8 message and see its received (checks if stack is
# functional after receiving a bad message)
for uid in alpha.remotes:
alpha.transmit(b'{"k3": "v3"}', uid, serialized=True)
looper.run(eventually(chkPrinted, betaP, {"k3": "v3"}))
示例3: testValidatorSuspensionByTrustee
def testValidatorSuspensionByTrustee(trustee, trusteeWallet, looper, nodeSet):
node = nodeSet[-1]
nodeNym = hexToFriendly(node.nodestack.verhex)
suspendNode(looper, trustee, trusteeWallet, nodeNym, node.name)
for n in nodeSet[:-1]:
looper.run(eventually(checkNodeNotInNodeReg, n, node.name))
looper.run(eventually(checkNodeNotInNodeReg, trustee, node.name))
示例4: testPrePrepareWithHighSeqNo
def testPrePrepareWithHighSeqNo(looper, txnPoolNodeSet, propagated1):
def chk():
for r in getNonPrimaryReplicas(txnPoolNodeSet, instId):
nodeSuspicions = len(getNodeSuspicions(
r.node, Suspicions.WRONG_PPSEQ_NO.code))
assert nodeSuspicions == 1
def checkPreprepare(replica, viewNo, ppSeqNo, req, numOfPrePrepares):
assert (replica.prePrepares[viewNo, ppSeqNo][0]) == \
(req.identifier, req.reqId, req.digest)
primary = getPrimaryReplica(txnPoolNodeSet, instId)
nonPrimaryReplicas = getNonPrimaryReplicas(txnPoolNodeSet, instId)
req = propagated1.reqDigest
primary.doPrePrepare(req)
timeout = waits.expectedPrePrepareTime(len(txnPoolNodeSet))
for np in nonPrimaryReplicas:
looper.run(
eventually(checkPreprepare, np, primary.viewNo,
primary.lastPrePrepareSeqNo - 1, req, 1,
retryWait=.5, timeout=timeout))
newReqDigest = (req.identifier, req.reqId + 1, req.digest)
incorrectPrePrepareReq = PrePrepare(instId,
primary.viewNo,
primary.lastPrePrepareSeqNo + 2,
*newReqDigest,
get_utc_epoch())
primary.send(incorrectPrePrepareReq, TPCStat.PrePrepareSent)
timeout = waits.expectedPrePrepareTime(len(txnPoolNodeSet))
looper.run(eventually(chk, retryWait=1, timeout=timeout))
示例5: do_view_change_with_unaligned_prepare_certificates
def do_view_change_with_unaligned_prepare_certificates(
slow_nodes, nodes, looper, sdk_pool_handle, sdk_wallet_client):
"""
Perform view change with some nodes reaching lower last prepared certificate than others.
With current implementation of view change this can result with view change taking a lot of time.
"""
fast_nodes = [n for n in nodes if n not in slow_nodes]
all_stashers = [n.nodeIbStasher for n in nodes]
slow_stashers = [n.nodeIbStasher for n in slow_nodes]
# Delay some PREPAREs and all COMMITs
with delay_rules(slow_stashers, pDelay()):
with delay_rules(all_stashers, cDelay()):
# Send request
request = sdk_send_random_request(looper, sdk_pool_handle, sdk_wallet_client)
# Wait until this request is prepared on fast nodes
looper.run(eventually(check_last_prepared_certificate, fast_nodes, (0, 1)))
# Make sure its not prepared on slow nodes
looper.run(eventually(check_last_prepared_certificate, slow_nodes, None))
# Trigger view change
for n in nodes:
n.view_changer.on_master_degradation()
# Now commits are processed
# Wait until view change is complete
looper.run(eventually(check_view_change_done, nodes, 1, timeout=60))
# Finish request gracefully
sdk_get_reply(looper, request)
示例6: test_request_older_than_stable_checkpoint_removed
def test_request_older_than_stable_checkpoint_removed(chkFreqPatched, looper, txnPoolNodeSet, sdk_pool_handle,
sdk_wallet_steward, reqs_for_checkpoint):
timeout = waits.expectedTransactionExecutionTime(len(txnPoolNodeSet))
max_batch_size = chkFreqPatched.Max3PCBatchSize
# Send some requests (insufficient for checkpoint),
# wait replies and check that current checkpoint is not stable
sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_steward, 2 * max_batch_size)
looper.run(eventually(chkChkpoints, txnPoolNodeSet, 1, retryWait=1, timeout=timeout))
checkRequestCounts(txnPoolNodeSet, 2 * max_batch_size, 2)
# From the steward send a request creating a user with None role
sdk_wallet_user = sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_steward)
looper.run(eventually(chkChkpoints, txnPoolNodeSet, 1, retryWait=1, timeout=timeout))
checkRequestCounts(txnPoolNodeSet, 2 * max_batch_size + 1, 3)
# From the created user send a request creating another user.
# Dynamic validation of this request must fail since a user with None role cannot create users.
# However, the 3PC-batch with the sent request must be ordered.
with pytest.raises(RequestRejectedException):
sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_user)
looper.run(eventually(chkChkpoints, txnPoolNodeSet, 1, retryWait=1, timeout=timeout))
checkRequestCounts(txnPoolNodeSet, 2 * max_batch_size + 2, 4)
# Send more requests to cause checkpoint stabilization
sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_steward, max_batch_size)
# Check that checkpoint is stable now
# and verify that requests for it were removed
looper.run(eventually(chkChkpoints, txnPoolNodeSet, 1, 0, retryWait=1, timeout=timeout))
checkRequestCounts(txnPoolNodeSet, 0, 0)
# Send more requests to cause new checkpoint
sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_steward, reqs_for_checkpoint + 1)
looper.run(eventually(chkChkpoints, txnPoolNodeSet, 2, 0, retryWait=1, timeout=timeout))
checkRequestCounts(txnPoolNodeSet, 1, 1)
示例7: testRescheduleUpgradeToLowerVersionThanPreviouslyScheduled
def testRescheduleUpgradeToLowerVersionThanPreviouslyScheduled(
looper, tconf, nodeSet, validUpgrade, trustee, trusteeWallet):
"""
A node starts at version 1.2 running has scheduled upgrade for version 1.5
but get a txn for upgrade 1.4, it will schedule it and cancel upgrade to 1.5.
"""
upgr1 = deepcopy(validUpgrade)
upgr2 = deepcopy(upgr1)
upgr2[VERSION] = bumpVersion(upgr1[VERSION])
upgr2[NAME] += randomString(3)
# upgr2[SHA256] = get_valid_code_hash()
upgr2[SHA256] = 'ef9c3984e7a31994d4f692139116120bd0dd1ff7e270b6a2d773f8f2f9214d4c'
# An upgrade for higher version scheduled, it should pass
ensureUpgradeSent(looper, trustee, trusteeWallet, upgr2)
looper.run(
eventually(
checkUpgradeScheduled,
nodeSet,
upgr2[VERSION],
retryWait=1,
timeout=waits.expectedUpgradeScheduled()))
# An upgrade for lower version scheduled, the transaction should pass and
# the upgrade should be scheduled
ensureUpgradeSent(looper, trustee, trusteeWallet, upgr1)
looper.run(
eventually(
checkUpgradeScheduled,
nodeSet,
upgr1[VERSION],
retryWait=1,
timeout=waits.expectedUpgradeScheduled()))
示例8: test_send_proof_works
def test_send_proof_works(aliceAgent, aliceAcceptedFaber, aliceAcceptedAcme,
acmeAgent, emptyLooper):
# 1. request Claims from Faber
faberLink = aliceAgent.wallet.getLink('Faber College')
name, version, origin = faberLink.availableClaims[0]
schemaKey = SchemaKey(name, version, origin)
aliceAgent.sendReqClaim(faberLink, schemaKey)
# 2. check that claim is received from Faber
async def chkClaims():
claim = await aliceAgent.prover.wallet.getClaimSignature(ID(schemaKey))
assert claim.primaryClaim
emptyLooper.run(eventually(chkClaims, timeout=waits.expectedClaimsReceived()))
# 3. send Proof Request to Alice
alice_link = acmeAgent.wallet.getLink('Alice')
acmeAgent.sendProofReq(alice_link, 'Job-Application-v0.3')
def chkProofRequest():
assert len(aliceAgent.wallet.getMatchingLinksWithProofReq("Job-Application-2", "Acme Corp")) > 0
emptyLooper.run(eventually(chkProofRequest, timeout=waits.expectedClaimsReceived()))
# 4. send proof to Acme
acme_link, acme_proof_req = aliceAgent.wallet.getMatchingLinksWithProofReq("Job-Application-2", "Acme Corp")[0]
aliceAgent.sendProof(acme_link, acme_proof_req)
# 5. check that proof is verified by Acme
def chkProof():
internalId = acmeAgent.get_internal_id_by_nonce(acme_link.invitationNonce)
link = acmeAgent.wallet.getLinkBy(internalId=internalId)
assert "Job-Application-2" in link.verifiedClaimProofs
emptyLooper.run(eventually(chkProof, timeout=waits.expectedClaimsReceived()))
示例9: testOrderingCase1
def testOrderingCase1(looper, txnPoolNodeSet, sdk_wallet_client, sdk_pool_handle):
"""
Scenario -> PRE-PREPARE not received by the replica, Request not received
for ordering by the replica, but received enough commits to start ordering.
It queues up the request so when a PRE-PREPARE is received or request is
receievd for ordering, an order can be triggered
https://www.pivotaltracker.com/story/show/125239401
Reproducing by - Pick a node with no primary replica, replica ignores
forwarded request to replica and delay reception of PRE-PREPARE sufficiently
so that enough COMMITs reach to trigger ordering.
"""
delay = 10
replica = getNonPrimaryReplicas(txnPoolNodeSet, instId=0)[0]
delaysPrePrepareProcessing(replica.node, delay=delay, instId=0)
def doNotProcessReqDigest(self, _):
pass
patchedMethod = types.MethodType(doNotProcessReqDigest, replica)
replica.processRequest = patchedMethod
def chk(n):
assert replica.spylog.count(replica.doOrder.__name__) == n
sdk_send_random_request(looper, sdk_pool_handle, sdk_wallet_client)
timeout = delay - 5
looper.run(eventually(chk, 0, retryWait=1, timeout=timeout))
timeout = delay + 5
looper.run(eventually(chk, 1, retryWait=1, timeout=timeout))
示例10: test_resend_instance_change_messages
def test_resend_instance_change_messages(looper,
txnPoolNodeSet,
tconf,
sdk_wallet_steward,
sdk_pool_handle):
primary_node = txnPoolNodeSet[0]
old_view_no = checkViewNoForNodes(txnPoolNodeSet, 0)
assert primary_node.master_replica.isPrimary
for n in txnPoolNodeSet:
n.nodeIbStasher.delay(icDelay(3 * tconf.INSTANCE_CHANGE_TIMEOUT))
assert set([n.view_changer.instance_change_rounds for n in txnPoolNodeSet]) == {0}
disconnect_node_and_ensure_disconnected(looper,
txnPoolNodeSet,
primary_node,
stopNode=False)
txnPoolNodeSet.remove(primary_node)
looper.run(eventually(partial(check_count_connected_node, txnPoolNodeSet, 4),
timeout=5,
acceptableExceptions=[AssertionError]))
looper.runFor(2*tconf.INSTANCE_CHANGE_TIMEOUT)
assert set([n.view_changer.instance_change_rounds for n in txnPoolNodeSet]) == {1}
looper.runFor(tconf.INSTANCE_CHANGE_TIMEOUT)
looper.run(eventually(partial(checkViewNoForNodes, txnPoolNodeSet, expectedViewNo=old_view_no + 1),
timeout=tconf.VIEW_CHANGE_TIMEOUT))
sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_steward, 5)
ensure_all_nodes_have_same_data(looper, txnPoolNodeSet)
示例11: test_api
def test_api():
loop = asyncio.get_event_loop()
with pytest.raises(PlenumValueError):
loop.run_until_complete(eventually(lambda x: True, timeout=0))
with pytest.raises(PlenumValueError):
loop.run_until_complete(eventually(lambda x: True, timeout=250))
loop.close()
示例12: nymsAddedInQuickSuccession
def nymsAddedInQuickSuccession(nodeSet, addedTrustAnchor, looper,
trustAnchor, trustAnchorWallet):
usigner = DidSigner()
nym = usigner.verkey
idy = Identity(identifier=nym)
trustAnchorWallet.addTrustAnchoredIdentity(idy)
# Creating a NYM request with same nym again
req = idy.ledgerRequest()
trustAnchorWallet._pending.appendleft((req, idy.identifier))
reqs = trustAnchorWallet.preparePending()
trustAnchor.submitReqs(*reqs)
def check():
assert trustAnchorWallet._trustAnchored[nym].seqNo
timeout = waits.expectedTransactionExecutionTime(len(nodeSet))
looper.run(eventually(check, timeout=timeout))
timeout = waits.expectedReqNAckQuorumTime()
looper.run(eventually(checkNacks,
trustAnchor,
req.reqId,
"is already added",
retryWait=1, timeout=timeout))
count = 0
for node in nodeSet:
for seq, txn in node.domainLedger.getAllTxn():
if txn[TXN_TYPE] == NYM and txn[TARGET_NYM] == usigner.identifier:
count += 1
assert(count == len(nodeSet))
示例13: testMultipleInstanceChangeMsgsMarkNodeAsSuspicious
def testMultipleInstanceChangeMsgsMarkNodeAsSuspicious(looper, txnPoolNodeSet):
maliciousNode = txnPoolNodeSet[0]
for i in range(0, 5):
maliciousNode.send(maliciousNode.view_changer._create_instance_change_msg(i, 0))
def chk(instId):
for node in txnPoolNodeSet:
if node.name != maliciousNode.name:
args = getAllArgs(node, ViewChanger.process_instance_change_msg)
assert len(args) == 5
for arg in args:
assert arg['frm'] == maliciousNode.name
numOfNodes = len(txnPoolNodeSet)
instanceChangeTimeout = waits.expectedPoolViewChangeStartedTimeout(
numOfNodes)
for i in range(0, 5):
looper.run(eventually(chk, i, retryWait=1,
timeout=instanceChangeTimeout))
def g():
for node in txnPoolNodeSet:
if node.name != maliciousNode.name:
frm, reason, code = getAllArgs(node, Node.reportSuspiciousNode)
assert frm == maliciousNode.name
assert isinstance(reason, SuspiciousNode)
suspectingNodes = \
getNodeSuspicions(node,
Suspicions.FREQUENT_INST_CHNG.code)
assert len(suspectingNodes) == 13
timeout = waits.expectedTransactionExecutionTime(numOfNodes)
looper.run(eventually(g, retryWait=1, timeout=timeout))
示例14: testPropagateRecvdBeforeRequest
def testPropagateRecvdBeforeRequest(setup, looper, txnPoolNodeSet, sent1):
A, B, C, D = txnPoolNodeSet
def x():
# A should not have received a request from the client
assert len(recvdRequest(A)) == 0
# A should have received only one PROPAGATE
assert len(recvdPropagate(A)) == 1
# A should have sent only one PROPAGATE
assert len(sentPropagate(A)) == 1
timeout = waits.expectedNodeToNodeMessageDeliveryTime() + delaySec - 2
looper.run(eventually(x, retryWait=.5, timeout=timeout))
def y():
# A should have received a request from the client
assert len(recvdRequest(A)) == 1
# A should still have sent only one PROPAGATE
assert len(sentPropagate(A)) == 1
timeout = waits.expectedNodeToNodeMessageDeliveryTime() + delaySec + 2
looper.run(eventually(y, retryWait=.5, timeout=timeout))
def chk():
# A should have forwarded the request
assertLength(forwardedRequest(A), 1)
timeout = waits.expectedClientRequestPropagationTime(
len(txnPoolNodeSet)) + delaySec
looper.run(eventually(chk, retryWait=1, timeout=timeout))
auth_obj = A.authNr(0).core_authenticator
auth_calling_count = get_count(auth_obj, auth_obj.authenticate)
assert auth_calling_count == reqCount
示例15: do_view_change_with_delayed_commits_on_all_but_one
def do_view_change_with_delayed_commits_on_all_but_one(nodes, nodes_without_one_stashers,
except_node,
looper,
sdk_pool_handle,
sdk_wallet_client):
new_view_no = except_node.viewNo + 1
old_last_ordered = except_node.master_replica.last_ordered_3pc
# delay commits for all nodes except node X
with delay_rules(nodes_without_one_stashers, cDelay(sys.maxsize)):
# send one request
requests2 = sdk_send_random_requests(looper, sdk_pool_handle,
sdk_wallet_client, 1)
def last_ordered(node: Node, last_ordered):
assert node.master_replica.last_ordered_3pc == last_ordered
# wait until except_node ordered txn
looper.run(
eventually(last_ordered, except_node, (except_node.viewNo,
old_last_ordered[1] + 1)))
# trigger view change on all nodes
for node in nodes:
node.view_changer.on_master_degradation()
# wait for view change done on all nodes
looper.run(eventually(view_change_done, nodes, new_view_no))
sdk_get_replies(looper, requests2)