本文整理汇总了Python中TestUtils.didReceive方法的典型用法代码示例。如果您正苦于以下问题:Python TestUtils.didReceive方法的具体用法?Python TestUtils.didReceive怎么用?Python TestUtils.didReceive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestUtils
的用法示例。
在下文中一共展示了TestUtils.didReceive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testEnclaveBridge
# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import didReceive [as 别名]
def testEnclaveBridge(self):
'''Create a node that can bridge between the enclaves
Send a flooding message from it to 1 enclave and verify only nodes in that one got it
'''
authenticationPayload = "This is a test"
# Build the bridge node
(status, bridgeNode, observer) = yield TestUtils.startupClientNode(self.myIP, 12500, allEnclaves[0], self.bsNode1.nodeLocation)
self.failUnless(status, 'testEnclave bridge could not join first bootstrap [%s]' % status)
# Join the other enclave also.
enableAutoDiscovery = True
bootstrapNodeList = [ self.bsNode2.nodeLocation ]
status = yield bridgeNode.joinEnclave(bootstrapNodeList, enableAutoDiscovery, authenticationPayload, False, None)
self.failUnless(status, 'testEnclave bridge could not join second bootstrap [%s]' % status)
self.bridgeNode = bridgeNode # Store a reference
# Send a flooding message to one enclave and verify only one got it.
messageNum = random.randint(1,9999999)
status = yield TestUtils.sendFlood(bridgeNode,messageNum, allEnclaves[0] )
self.assertTrue(status,"sendFlood failed!")
yield TestUtils.wait(3) # Wait for the messages to send
# Check message counts
status = TestUtils.didReceive(self.allNodeObservers, allEnclaves[0], messageNum, numNodes)
self.assertTrue(status,"Nodes in enclave %s didn't all recv message")
status = TestUtils.didNotReceive(self.allNodeObservers, allEnclaves[1], messageNum, numNodes)
self.assertTrue(status,"Some Nodes in enclave %s did recv message")
示例2: testEnclaveFlooding
# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import didReceive [as 别名]
def testEnclaveFlooding(self):
"""Build 2 enclaves and test flooding to each and all."""
global startingPort
# Create Bootstrap
port = 12345
bootstrapNodeLocation = NodeLocation(None, self.myIP, port)
allNodes = []
allNodeObservers = []
allBootstrapObservers = []
self.allNodes = allNodes
# Start a bootstrap node
(status, bsNode, observer) = yield TestUtils.startupBootstrapNode(self.myIP, port, allEnclaves[0])
self.assertTrue(status, "Could not build bootstrap node")
allBootstrapObservers.append(observer)
self.bsNode = bsNode
# Join another enclave
bootstrapNodeList = None
enableAutoDiscovery = True
status = yield self.bsNode.joinEnclave(
bootstrapNodeList, enableAutoDiscovery, None, isBootstrapNode=True, enclaveStr=allEnclaves[1]
)
# Add X nodes to each enclave
for enclave in allEnclaves:
for _ in range(numNodes):
# Add a node to the enclave
(status, node, observer) = yield TestUtils.startupClientNode(
self.myIP, startingPort, enclave, bootstrapNodeLocation
)
self.assertTrue(status, "Could not startupClientNode")
startingPort += 1
allNodes.append(node)
allNodeObservers.append(observer)
# Wait for flooding to reach all the nodes
waiter = ConnectivityCounter()
numberOfNodes = len(allEnclaves) * numNodes
yield waiter.waitForConnectivity(numberOfNodes, bsNode) # Does not count bsNode itself.
# Flood from bootstrap to all
messageNum = random.randint(1, 9999999)
status = yield TestUtils.sendFlood(bsNode, messageNum, "ALL")
self.assertTrue(status, "sendFlood failed!")
yield TestUtils.wait(3) # Wait for the messages to send
# Check message counts
status = TestUtils.didReceive(allNodeObservers, "ALL", messageNum, numberOfNodes)
self.assertTrue(status, "All nodes did not receive message")
# Flood from bootstrap to single enclave
messageNum = random.randint(1, 9999999)
status = yield TestUtils.sendFlood(bsNode, messageNum, allEnclaves[0])
self.assertTrue(status, "sendFlood failed!")
yield TestUtils.wait(3) # Wait for the messages to send
# Check message counts
status = TestUtils.didReceive(allNodeObservers, allEnclaves[0], messageNum, numNodes)
self.assertTrue(status, "Nodes in enclave %s didn't all recv message")
status = TestUtils.didNotReceive(allNodeObservers, allEnclaves[1], messageNum, numNodes)
self.assertTrue(status, "Some Nodes in enclave %s did recv message")
log.msg("\n\n\n TEST ARE ALL DONE \n\n\n")
yield TestUtils.wait(60)
# Stop everything
for node in self.allNodes:
yield node.leave()
yield self.bsNode.leave()
# Wait for all network timeouts to finish
yield TestUtils.wait(Config.CONNECTION_CACHE_DELAY + 3)
# self.flushLoggedErrors()
defer.returnValue(True)