def run(self): node_a_ip = self.node_a.ip node_b_ip = self.node_b.ip print_t(node_a_ip, "Starting thread...") print_t( node_a_ip, "Adding node {0} as a neighbour to {1}".format( node_b_ip, node_a_ip)) print_t( node_a_ip, "Attempting to connect to node: http://{0}:14265".format( node_a_ip)) try_again = True while try_again and self.retries > 0: try: api = Iota("http://{0}:14265".format(node_a_ip)) api.add_neighbors(["udp://{0}:14777".format(node_b_ip)]) self.node_a.connected_nodes.append(node_b_ip) print_t( node_a_ip, "Added node {0} as a neighbour to {1}".format( node_b_ip, node_a_ip)) try_again = False except: self.retries -= 1 print_t(node_a_ip, ERROR_MSG.format(node_a_ip, self.delay, self.retries)) try_again = True if self.retries != 0: time.sleep(self.delay) print_t(node_a_ip, "Exiting thread.")
def test_wireup(self): """ Verify that the command is wired up correctly. (sync) The API method indeed calls the appropiate command. """ with patch( 'iota.commands.core.add_neighbors.AddNeighborsCommand.__call__', MagicMock(return_value=async_return( 'You found me!'))) as mocked_command: api = Iota(self.adapter) response = api.add_neighbors('test_uri') self.assertTrue(mocked_command.called) self.assertEqual(response, 'You found me!')