def testPingResetsTimeout(self): clock = task.Clock() a = pb.PingableAvatar(avatarId=None, clock=clock) a.setMind(self.mind) clock.advance(self.pingCheckInterval) # ping broker = tpb.Broker() d = a.perspectiveMessageReceivedUnserialised(broker, 'ping', (), {}) d.addCallback(broker.unserialize) def cb(result): self.assertEquals(result, True) clock.advance(self.pingCheckInterval) self.assert_(not self.mind.disconnected) clock.advance(self.pingCheckInterval) self.assert_(self.mind.disconnected) d.addCallback(cb) return d
def testNoPing(self): clock = task.Clock() a = pb.PingableAvatar(avatarId=None, clock=clock) a.setMind(self.mind) self.assert_(not self.mind.disconnected) clock.advance(self.pingCheckInterval) self.assert_(not self.mind.disconnected) clock.advance(self.pingCheckInterval) self.assert_(self.mind.disconnected)
def testMessageReceivedUnserialisedResetsTimeout(self): clock = task.Clock() a = pb.PingableAvatar(avatarId=None, clock=clock) a.perspective_test = lambda: True a.setMind(self.mind) clock.advance(self.pingCheckInterval) # this should reset the ping timeout d = a.perspectiveMessageReceivedUnserialised(tpb.Broker(), 'test', (), {}) clock.advance(self.pingCheckInterval) self.assert_(not self.mind.disconnected) clock.advance(self.pingCheckInterval) self.assert_(self.mind.disconnected)
def testSuccessfulMindRemoteAnswerResetsTimeout(self): clock = task.Clock() a = pb.PingableAvatar(avatarId=None, clock=clock) a.setMind(self.mind) clock.advance(self.pingCheckInterval) d, remote_result = a.mindCallRemote('test'), [None] def cb(result): remote_result[0] = result d.addCallback(cb) # this should reset the ping timeout self.mind.callback(True) self.assertEquals(remote_result, [True]) clock.advance(self.pingCheckInterval) self.assert_(not self.mind.disconnected) clock.advance(self.pingCheckInterval) self.assert_(self.mind.disconnected)