def ensure_all_alive(network: Network, backend: Backend) -> None: log.debug("Ensuring all nodes in the network are alive") ids = network.ids() for attempt in range(NUM_ATTEMPTS): commands = [ CliCommand(node_id, ["list-neighbours"]) for node_id in ids ] results = backend.run_commands(commands) ids = [ result.command.node_id for result in results if not result.successful() ] if not ids: log.debug("All nodes ensured alive") return log.debug( "At attempt %d/%d, still %d nodes not responding. Sleeping %d seconds.", attempt + 1, NUM_ATTEMPTS, len(ids), ATTEMPT_WAIT_SECS, ) time.sleep(ATTEMPT_WAIT_SECS) raise AssertionError( f"{len(ids)} nodes still didn't reply after all attempts")
def __build_report( network: Network, results: TestResult, main_graph_path: Path, query_graph_paths: Dict[str, Path], ) -> Dict[str, Any]: report: Dict[str, Any] = { "key_ids": [node_id.key_id for node_id in network.ids()], "graph": str(main_graph_path), "success_percentage": results.success_percentage, "average_num_requests": results.average_num_requests, "average_search_times_sec": results.average_search_times_sec, "searches": [], } for search_result in results.search_results: report["searches"].append({ "from_id": search_result.from_id.key_id, "to_id": search_result.to_id.key_id, "success": search_result.success, "message_id": search_result.message_id, "num_requests": search_result.num_requests, "search_times_sec": search_result.search_times_sec, "graph": str(query_graph_paths[search_result.message_id]), }) return report
def connect_network(network: Network, backend: Backend) -> None: log.info("Connecting network together") ensure_all_alive(network, backend) for i in range(network.num_connects): log.info(f"Performing connection {i + 1}/{network.num_connects}") ids = network.ids() if network.connect_type == ConnectType.CYCLICAL: connections = list(zip(ids[:-1], ids[1:])) elif network.connect_type == ConnectType.ROOTED: [root_id] = network.random_ids(1) connections = [(i, root_id) for i in ids] else: raise AssertionError() commands = [ CliCommand(a, ["connect", "--key", b.key_id, "--address", backend.get_ip_address(b),],) for a, b in connections ] results = backend.run_commands(commands) num_failed = sum(not result.successful() for result in results) log.info("Out of %d connections, %d failed", len(connections), num_failed)