本文整理汇总了Python中TestUtils.wait方法的典型用法代码示例。如果您正苦于以下问题:Python TestUtils.wait方法的具体用法?Python TestUtils.wait怎么用?Python TestUtils.wait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestUtils
的用法示例。
在下文中一共展示了TestUtils.wait方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testNodeStartup
# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import wait [as 别名]
def testNodeStartup(self):
# Start a bootstrap node
(status, self.bsNode, _observer) = yield TestUtils.startupBootstrapNode(self.myIP, 12345, 'localhost')
self.assertTrue(status, 'Could not build bootstrap node')
# Start a client node
(status, self.normalNode, observer) = yield TestUtils.startupClientNode(self.myIP, 12346, 'localhost', self.bsNode.nodeLocation)
self.assertTrue(status, 'Could not startupClientNode')
# Are they connected together?
status = yield self.doQuickSendTest()
self.assertTrue(status, 'doQuickSendTest')
# Stop the nodes
yield self.normalNode.leave()
yield self.bsNode.leave()
# Wait for the connections to really all close
if Config.USE_CONNECTION_CACHE:
yield TestUtils.wait(Config.CONNECTION_CACHE_DELAY + 3)
else:
yield TestUtils.wait(3)
defer.returnValue(True)
示例2: testNodeStartup
# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import wait [as 别名]
def testNodeStartup(self):
port = 12345
enclave = 'localhost'
bootstrapNodeLocation = NodeLocation(None, self.myIP, port)
# Start a bootstrap node
(status, bsNode, _) = yield TestUtils.startupBootstrapNode(self.myIP, port, enclave)
self.assertTrue(status, 'Could not build bootstrap node')
# Start a client node
(status, node, _) = yield TestUtils.startupClientNode(self.myIP, 12346, enclave, bootstrapNodeLocation)
self.assertTrue(status, 'Could not startupClientNode')
#yield TestUtils.wait(3)
# Are they connected together?
status = yield self.doConnectionTest(node)
self.assertTrue(status, 'doConnectionTest')
# Stop the nodes
yield bsNode.leave()
yield node.leave()
yield TestUtils.wait(Config.CONNECTION_CACHE_DELAY + 3)
defer.returnValue(True)
示例3: getAggResponse
# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import wait [as 别名]
def getAggResponse(self):
'''Send a query and get an agg response from all the nodes.'''
bsNode = self.bsNetwork.chordNode
for aggNumber in range(1, numNodes + 5):
# Reset the message counter
obs = self.getObserver(bsNode, self.allTestObservers)
obs.resetMessageCount()
# Send the query asking for a response
messageNum = aggNumber # Just to keep it incrementing
yield TestUtils.sendFlood(bsNode,messageNum,'localhost', data="SEND_AGG_RESPONSE:%d" % aggNumber)
# Now check how many messages the bootstrap node got in return
for _ in range(10): # 10 seconds
recvCount = obs.getMessageCount()
if recvCount >= numNodes+1:
break
else:
yield TestUtils.wait(1)
self.failUnless(recvCount == numNodes+1, "getAggResponse didn't get the correct number of messages back.Expected[%d] Got[%d]" % (numNodes+1, recvCount))
defer.returnValue(True)
示例4: waitForConnectivity
# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import wait [as 别名]
def waitForConnectivity(self, numToWaitFor, chordNode):
'''Wait till we can connect to all numNodes'''
self.node = chordNode
self.testCounter = 1
self.connectedNodeList = []
# Need to see the messages
self.node.addMessageObserver(self.messageReceived)
yield self.getNumConnected()
while len(self.connectedNodeList) < numToWaitFor:
log.msg("DEBUG: waiting for %d nodes. Got %d" % (numToWaitFor, len(self.connectedNodeList)), system="ConnectivityCounter")
self.testCounter += 1
yield self.getNumConnected()
yield TestUtils.wait(5) # Wait for messages to go around
log.msg("DEBUG: waiting for %d nodes. Got %d" % (numToWaitFor, len(self.connectedNodeList)), system="ConnectivityCounter")
# for n in self.connectedNodeList:
# print("DEBUG: Node:%s" % n)
# Don't care anymore
self.node.removeMessageObserver(self.messageReceived)
示例5: waitForAllReceived
# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import wait [as 别名]
def waitForAllReceived(self):
'''Wait until all messages have been received by all the nodes.'''
numTries = 10
expectedNumMsg = numNodes*numMessages
for _ in range(numTries):
completedObservers = 0
incompleteObservers = 0
# Wait a sec
yield TestUtils.wait(1)
# Count them
for obs in self.allObservers:
numRx = obs.getNumReceived()
if numRx == expectedNumMsg:
completedObservers += 1
elif numRx > expectedNumMsg:
obs.printMessages()
raise Exception("Programming error... received more messages than possible! Got[%d] Expected[%d]" % (numRx,expectedNumMsg ))
else:
incompleteObservers += 1
print("waitForAllReceived: Complete:%d Incomplete:%d" % (completedObservers, incompleteObservers))
if incompleteObservers == 0:
defer.returnValue(True)
defer.returnValue(False)
示例6: testSerialP2PSending
# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import wait [as 别名]
def testSerialP2PSending(self):
# Start a bootstrap node
(status, self.bsNode, _observer) = yield TestUtils.startupBootstrapNode(self.myIP, 12345, 'localhost')
self.assertTrue(status, 'Could not build bootstrap node')
self.allNodes.append(self.bsNode)
self.bsNode.addMessageObserver(self.messageReceived)
# Start client nodes
log.msg("Building nodes...")
for i in range(numNodes):
(status, node, observer) = yield TestUtils.startupClientNode(self.myIP, 12346+i, 'localhost', self.bsNode.nodeLocation)
self.assertTrue(status, 'Could not startupClientNode')
self.allNodes.append(node)
# Wait for flooding to reach all the nodes
waiter = ConnectivityCounter()
yield waiter.waitForConnectivity(numNodes, self.bsNode) # Does not count bsNode itself.
# Do the real test
status = yield self.doStressTest()
# Now close it all down!
yield self.allLeave()
# Wait a second or two
yield TestUtils.wait(3+Config.CONNECTION_CACHE_DELAY)
defer.returnValue(True)
示例7: testSerialFlooding
# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import wait [as 别名]
def testSerialFlooding(self):
# Start a bootstrap node
(status, self.bsNode, _observer) = yield TestUtils.startupBootstrapNode(self.myIP, 12345, 'localhost')
self.assertTrue(status, 'Could not build bootstrap node')
self.allNodes.append(self.bsNode)
self.bsNode.addMessageObserver(self.messageReceived)
# Start client nodes
for i in range(numNodes):
(status, node, observer) = yield TestUtils.startupClientNode(self.myIP, 12346+i, 'localhost', self.bsNode.nodeLocation)
self.assertTrue(status, 'Could not startupClientNode')
self.allNodes.append(node)
observer = MyMessageObserver()
node.addMessageObserver(observer.messageReceived)
observer.node = node
self.allObservers.append(observer)
# Wait for flooding to reach all the nodes
waiter = ConnectivityCounter()
yield waiter.waitForConnectivity(numNodes, self.bsNode) # Does not count bsNode itself.
# Now do the stress test
status = yield self.doStressTest()
# Now close it all down!
yield self.allLeave()
# Wait a second or two for network timeouts
yield TestUtils.wait(9)
defer.returnValue(True)
示例8: waitForMessageCount
# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import wait [as 别名]
def waitForMessageCount(self, obs, numMessagesToWaitFor):
for _ in range(10):
if obs.getPingbackCount() >= numMessagesToWaitFor:
defer.returnValue(True)
else:
yield TestUtils.wait(1)
defer.returnValue(False)
示例9: testAggregationMessageAPI
# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import wait [as 别名]
def testAggregationMessageAPI(self):
'''
By the time this function is called, we should have a full network built and connected.
Tests to perform now:
1. Send P2P messages from BS Node to all nodes
2. Send P2P messages from all Nodes to BSNode
3. Send flooding from BSNode to all
4. Send query and return aggregation responses of different levels
Finally, do cleanup.
'''
try:
# Build a network
yield self.buildNetwork()
# 1. Send P2P messages from BS Node to all nodes
yield self.p2pFromBStoAll()
# 2. Send P2P messages from all Nodes to BSNode
yield self.p2pFromAlltoBS()
# 3. Send flooding from BSNode to all
yield self.floodFromBStoAll()
# 4. Send query and return aggregation responses of different levels
yield self.getAggResponse()
# Do the cleanup
yield TestUtils.wait(5)
# Shut it all down
for (_clientAPI, networkAPI) in self.allNodes:
yield networkAPI.disconnect()
yield self.bsNetwork.disconnect()
# Now wait for the network cache disconnect timeout
yield TestUtils.wait(Config.CONNECTION_CACHE_DELAY + 5)
except Exception, e:
log.err(e, "An error occurred in testAggregationMessageAPI")
示例10: testDisconnectedBootstraps
# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import wait [as 别名]
def testDisconnectedBootstraps(self):
'''Create a BS node and some clients. Create another bootstrap node and some clients (so we essentially have two rings).
Verify, that the bootstrap nodes autodiscover each other and connect together
'''
global startingPort
# Create Bootstrap
port = 12345
bootstrapNodeLocation = NodeLocation(None, self.myIP, port)
bootstrapNodeLocation2 = NodeLocation(None, self.myIP, port+1)
self.allNodes = []
self.allMetricsObservers = []
self.allTestObservers = []
# Build the BS node
(status, bsClientAPI, bsNetworkAPI) = yield TestUtils.startNodeUsingAPI(bootstrapNodeLocation.ip, bootstrapNodeLocation.port, None, 'theEnclave', True, True)
self.allMetricsObservers.append(MetricsMessageObserver(bsNetworkAPI.chordNode))
self.assertTrue(status, 'Could not build bootstrap node')
# Build second BS node
(status, bsClientAPI2, bsNetworkAPI2) = yield TestUtils.startNodeUsingAPI(bootstrapNodeLocation2.ip, bootstrapNodeLocation2.port, None, 'theEnclave', True, True)
self.allMetricsObservers.append(MetricsMessageObserver(bsNetworkAPI2.chordNode))
self.assertTrue(status, 'Could not build bootstrap node 2')
# Build the client node
(status, clClientAPI, clNetworkAPI) = yield TestUtils.startNodeUsingAPI(self.myIP, port+2, bootstrapNodeLocation, 'theEnclave', False, False)
self.allMetricsObservers.append(MetricsMessageObserver(clNetworkAPI.chordNode))
self.assertTrue(status, 'Could not build client node')
# Build the client node
(status, clClientAPI2, clNetworkAPI2) = yield TestUtils.startNodeUsingAPI(self.myIP, port+3, bootstrapNodeLocation2, 'theEnclave', False, False)
self.allMetricsObservers.append(MetricsMessageObserver(clNetworkAPI2.chordNode))
self.assertTrue(status, 'Could not build client node')
# Wait for flooding to reach all the nodes
waiter = ConnectivityCounter()
yield waiter.waitForConnectivity(3, clNetworkAPI.chordNode) # Does not count clNode itself.
# Now shut everything down
yield clNetworkAPI.disconnect()
yield clNetworkAPI2.disconnect()
yield bsNetworkAPI.disconnect()
yield bsNetworkAPI2.disconnect()
if Config.USE_CONNECTION_CACHE:
yield TestUtils.waitForConnectionCache()
else:
yield TestUtils.wait(5)
defer.returnValue(True)
示例11: testDefaultEnclaveAPI
# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import wait [as 别名]
def testDefaultEnclaveAPI(self):
'''Create a node which should default to localhost as the enclave name. '''
global startingPort
# Create Bootstrap
port = 12345
bootstrapNodeLocation = NodeLocation(None, self.myIP, port)
self.allNodes = []
self.allMetricsObservers = []
self.allTestObservers = []
# Build the client and network objects
enclaveStr1 = None
self.bsClient = SampleClient(self.myIP, port, None)
self.bsNetwork = classChordNetworkChord(self.bsClient, port, self.myIP)
bsID = self.bsNetwork.generateNodeID(str(port), "WHO CARES") # Get the ID with the bits on it we need. Use "port" because it'll be uniq for tests
# Join the network
log.msg("---- Bootstrap Join 1 ---- ", system="testDefaultEnclaveAPI")
d = defer.Deferred()
callFunc = lambda x, payload: self.shouldSucceedCallback(x, payload, d, self.bsNetwork)
self.bsNetwork.start(callFunc, bsID, enclaveStr1, "authenticate:succeed", None, True, True)
yield d # Wait for join to succeed
# Now check that the node is part of localhost
enclave = yield self.bsNetwork.findEnclave(self.myIP, port)
self.assertEqual(enclave, "localhost", "testDefaultEnclaveAPI did not get localhost as enclave!")
# Now create a client node and have it ask the bootstrap node for the enclave
log.msg("---- Start Client 1 ---- ", system="testIPFindingAPI")
yield self.startClientNode(None, None, 12350+1, bootstrapNodeLocation, None)
# Check that it got enclave localhost
enclave = yield self.allNodes[0][1].findEnclave(self.myIP, 12350+1)
self.assertEqual(enclave, "localhost", "testDefaultEnclaveAPI: client did not get localhost as enclave!")
# Now shut everything down
for (_clientAPI, networkAPI) in self.allNodes:
yield networkAPI.disconnect()
yield self.bsNetwork.disconnect()
# Now wait for the network cache disconnect timeout
yield TestUtils.wait(Config.CONNECTION_CACHE_DELAY + 1)
defer.returnValue(True)
示例12: testIPFindingAPI
# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import wait [as 别名]
def testIPFindingAPI(self):
'''Create a node and ask the system to figure out it's IP from a bootstrap node. '''
global startingPort
# Create Bootstrap
port = 12345
bootstrapNodeLocation = NodeLocation(None, self.myIP, port)
self.allNodes = []
self.allMetricsObservers = []
self.allTestObservers = []
# Build the client and network objects
enclaveStr1 = "AnEnclave"
myIP = None # self.myIP
self.bsClient = SampleClient(myIP, port, None)
self.bsNetwork = classChordNetworkChord(self.bsClient, port, myIP)
bsID = self.bsNetwork.generateNodeID(str(port), "WHO CARES") # Get the ID with the bits on it we need. Use "port" because it'll be uniq for tests
# Join the network
log.msg("---- Bootstrap Join 1 ---- ", system="testDefaultEnclaveAPI")
d = defer.Deferred()
callFunc = lambda x, payload: self.shouldSucceedCallback(x, payload, d, self.bsNetwork)
self.bsNetwork.start(callFunc, bsID, enclaveStr1, "authenticate:succeed", None, True, False)
yield d # Wait for join to succeed
# Now create a client node which will get it's IP from the bootstrap node
log.msg("---- Start Client 1 ---- ", system="testIPFindingAPI")
yield self.startClientNode(None, None, 12350+1, bootstrapNodeLocation, enclaveStr1)
# Do a bit of verification
# Now shut everything down
for (_clientAPI, networkAPI) in self.allNodes:
rc = yield networkAPI.isConnected("ANY")
self.assertTrue(rc != False, "isConnected returned a False value in testIPFindingAPI")
# Now shut everything down
for (_clientAPI, networkAPI) in self.allNodes:
yield networkAPI.disconnect()
yield self.bsNetwork.disconnect()
# Now wait for the network cache disconnect timeout
yield TestUtils.wait(Config.CONNECTION_CACHE_DELAY + 1)
defer.returnValue(True)
示例13: testAggregationMessage
# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import wait [as 别名]
def testAggregationMessage(self):
'''
Send flooding message and ask for aggregation response.
'''
print("testAggregationMessage method starting...")
counter = 1
try:
d = defer.Deferred()
messageNum = random.randint(1,9999999)
# Reset message count
self.observer.resetMessageCount()
self.observer.printDebug = True
aggMax = numNodes + 2
#aggNumber = 3
for aggNumber in range(1, aggMax+1):
#if aggNumber == aggNumber:
# Flood from bootstrap to all nodes
for i in range(numMessages):
#d.addCallback(self.sendFlood, self.bsNode,messageNum+i,'theEnclave', data="SEND_AGG_RESPONSE:%d" % aggNumber)
yield self.sendFlood(None, self.bsNode,messageNum+i,'theEnclave', data="SEND_AGG_RESPONSE:%d" % aggNumber)
print("sending message %d", counter)
counter += 1
d.callback(True)
yield d
# Wait a few seconds
yield TestUtils.wait(5)
print("testAggregationMessage check results...")
# Now check the results
yield self.checkResults(aggMax)
except Exception, e:
self.anError(e)
示例14: doStressTest
# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import wait [as 别名]
def doStressTest(self):
'''Randomly pick two nodes and send a message between them. Verify that it goes.'''
print("Running parallel stress test: %d p2p messages" % numMessages)
messageCounter = 0
while messageCounter < numMessages:
if messageCounter % 100 == 0:
print("Running test %d of %d" % (messageCounter, numMessages))
statusList = []
for _ in range(numMessagesInBlock):
messageCounter += 1
(srcNode, dstNode) = random.sample(self.allNodes, 2)
# Build the envelope
env = CopyEnvelope()
env['ttl'] = datetime.datetime.now() + datetime.timedelta(minutes=10)
env['source'] = srcNode.nodeLocation
env['type'] = 'p2p'
env['destination'] = dstNode.nodeLocation.id
env['msgID'] = random.getrandbits(128) # TODO: Something better here!
msgText = "Test number %d " % messageCounter
statusList.append(srcNode.sendSyncMessage(msgText, env))
# Now wait for all of them to complete
dl = defer.DeferredList(statusList)
results = yield dl # Wait for it
# Now check all the return codes
for (success, _) in results:
#print("DEBUG: doStressTest Result is %s" % success)
self.assertTrue(success, "doStressTest Message returned False!" )
# Wait a bit... just to ease up a smidge.
yield TestUtils.wait(0.1)
defer.returnValue(True)
示例15: doTearDown
# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import wait [as 别名]
def doTearDown(self):
'''Tear down the network created during setup.'''
log.msg("tearDown begins...")
# Stop everything
for networkAPI in self.allNetworkAPIs:
yield networkAPI.disconnect()
yield self.bsNode.leave()
# Wait for all network timeouts to finish
#self.flushLoggedErrors()
if Config.USE_CONNECTION_CACHE:
yield TestUtils.wait(Config.CONNECTION_CACHE_DELAY + 2)
else:
yield TestUtils.defWait(3)
defer.returnValue(True)