当前位置: 首页>>代码示例>>Python>>正文


Python TestUtils.showOpenConnections方法代码示例

本文整理汇总了Python中TestUtils.showOpenConnections方法的典型用法代码示例。如果您正苦于以下问题:Python TestUtils.showOpenConnections方法的具体用法?Python TestUtils.showOpenConnections怎么用?Python TestUtils.showOpenConnections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestUtils的用法示例。


在下文中一共展示了TestUtils.showOpenConnections方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: doStressTest

# 需要导入模块: import TestUtils [as 别名]
# 或者: from TestUtils import showOpenConnections [as 别名]
    def doStressTest(self):
        '''Randomly pick two nodes and send a message between them. Verify that it goes.'''
        
        
        endTime = datetime.datetime.now() + datetime.timedelta(minutes=timeLimit)
        
        numMessages = 0
        msgText = dict()
        msgText['type'] = 'COUNT'
        #"Test number %d " % numMessages

        while self.keepRunning:
            
            numMessages += 1
            if numMessages % 100 == 0:
                remainingTime = endTime - datetime.datetime.now()
                log.msg("Running test message %d . Time remaining: %s" % (numMessages, remainingTime))
                #yield TestUtils.wait(1)
            
            if numMessages % 1000 == 0:                
                TestUtils.showOpenConnections()
            
            
            (srcNode, dstNode) = random.sample(self.allNodes, 2)

            # ------------------
            # P2P Test ----
            # ------------------

            # 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!
             
             
            status = yield srcNode.sendSyncMessage(msgText, env)                
            self.assertTrue(status, "Message [%s] -> [%s] returned False!" % (srcNode, dstNode))
         
            # Increment the number of messages dst node should have
            self.msgTracker[dstNode][0] = self.msgTracker[dstNode][0]  + 1
            
            # ------------------
            # Flooding Test ----
            # ------------------
            
            # Now also send a flooding message from the same node to all others
            env = CopyEnvelope()
            env['ttl'] = datetime.datetime.now() + datetime.timedelta(minutes=10)
            env['source'] = srcNode.nodeLocation
            env['type'] = 'flood'
            env['destination'] = None
            env['msgID'] = random.getrandbits(128)
            env['enclave'] = 'localhost'
            
            status = yield srcNode.sendFloodingMessage(msgText, env)                
            self.assertTrue(status, "Flooding Message [%s] returned False!" % srcNode)
            
            # Increment the number of messages all nodes should get
            for (_node, valList) in self.msgTracker.iteritems():
                #if _node != srcNode:
                valList[0] = valList[0]  + 1

        
            
        self.checkResults()
            
        defer.returnValue(True)
开发者ID:danfleck,项目名称:Class-Chord,代码行数:72,代码来源:OneHourTest.py


注:本文中的TestUtils.showOpenConnections方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。