def conn_setup(node: NeoNode): # at this point we should have a fully connected node, so lets try to simulate a connection lost by the other side with self.assertLogHandler('network', 10) as log: node.connectionLost(failure.Failure(error.ConnectionDone())) self.assertTrue( "disconnected normally with reason" in log.output[-1]) self.assertNotIn(self.addr, self.leader.DEAD_ADDRS) self.assertIn(self.addr, self.leader.KNOWN_ADDRS) self.assertNotIn(self.addr, self.leader.Peers) self.assertFalse(node.has_tasks_running())
def conn_setup(node: NeoNode): # at this point we should have a fully connected node, so lets try to simulate a connection lost by the other side with self.assertLogHandler('network', 10) as log: # setup last_connection, to indicate we've lost connection before node.address.last_connection = Address.Now( ) # returns a timestamp of utcnow() # now lose the connection node.connectionLost(failure.Failure(error.ConnectionLost())) self.assertIn("second connection lost within 5 minutes", log.output[-1]) self.assertIn(str(error.ConnectionLost()), log.output[-2]) self.assertIn(self.addr, self.leader.DEAD_ADDRS) self.assertNotIn(self.addr, self.leader.KNOWN_ADDRS) self.assertNotIn(self.addr, self.leader.Peers) self.assertFalse(node.has_tasks_running())
def conn_setup(node: NeoNode): with self.assertLogHandler('network', 10) as log: # setup last_connection, to indicate we've lost connection before node.address.last_connection = Address.Now( ) # returns a timestamp of utcnow() # setup the heartbeat data to have last happened 25 seconds ago # if we disconnect now we should get a premature disconnect node.start_outstanding_data_request[ HEARTBEAT_BLOCKS] = Address.Now() - 25 # now lose the connection node.connectionLost(failure.Failure(error.ConnectionLost())) self.assertIn("Premature disconnect", log.output[-2]) self.assertIn(str(error.ConnectionLost()), log.output[-1]) self.assertIn(self.addr, self.leader.DEAD_ADDRS) self.assertNotIn(self.addr, self.leader.KNOWN_ADDRS) self.assertNotIn(self.addr, self.leader.Peers) self.assertFalse(node.has_tasks_running())