def test_sync_pending(self): network = Network() server = PendingConnectionsServer(None, network) req_type = 0 final_failure_called = [False] node_info = Mock(key='1234', prv_addresses=["1.2.3.4"], pub_addr="1.2.3.4", pub_port=self.port) def final_failure(*args, **kwargs): final_failure_called[0] = True server.conn_established_for_type[req_type] = lambda x: x server.conn_failure_for_type[req_type] = server.final_conn_failure server.conn_final_failure_for_type[req_type] = final_failure server._is_address_accessible = Mock(return_value=True) server._add_pending_request(req_type, node_info, prv_port=node_info.prv_port, pub_port=node_info.pub_port, args={}) assert len(server.pending_connections) == 1 server._sync_pending() assert network.connected network.connected = False server.pending_connections = {} server._add_pending_request(req_type, self.node_info, prv_port=self.node_info.prv_port, pub_port=self.node_info.pub_port, args={}) assert len(server.pending_connections) == 1 pending_conn = next(iter(list(server.pending_connections.values()))) pending_conn.socket_addresses = [] server._sync_pending() assert not network.connected assert final_failure_called[0]
def test_sync_pending(self): network = Network() server = PendingConnectionsServer(None, network) req_type = 0 final_failure_called = [False] node_info = Mock() node_info.prv_addresses = ["1.2.3.4"] node_info.pub_addr = "1.2.3.4" node_info.pub_port = self.port def final_failure(_): final_failure_called[0] = True server.conn_established_for_type[req_type] = lambda x: x server.conn_failure_for_type[req_type] = server.final_conn_failure server.conn_final_failure_for_type[req_type] = final_failure server._add_pending_request(req_type, node_info, self.port, self.key_id, args={}) assert len(server.pending_connections) == 1 server._sync_pending() assert network.connected network.connected = False server.pending_connections = {} server._add_pending_request(req_type, node_info, self.port, self.key_id, args={}) assert len(server.pending_connections) == 1 pending_conn = next(server.pending_connections.itervalues()) pending_conn.socket_addresses = [] server._sync_pending() assert not network.connected assert final_failure_called[0]
def test_sync_listen(self): network = Network() server = PendingConnectionsServer(None, network) req_type = 0 server.listen_established_for_type[req_type] = lambda x: x server.listen_failure_for_type[req_type] = server.final_conn_failure server._add_pending_listening(req_type, self.port, {}) assert len(server.pending_listenings) == 1 pending_lis = server.pending_listenings[0] pending_lis.time = 0 server._sync_pending() assert len(server.pending_listenings) == 0 assert len(server.open_listenings) == 1 server.last_check_listening_time = 0 server._remove_old_listenings() assert network.stop_listening_called assert len(server.pending_listenings) == 0 assert len(server.open_listenings) == 0