def test_websocket_reconnect(random_mesh): nodeX = Node("nodeX", connections=["node1"], stats_enable=True, stats_port=random_port(), listen=f"ws://127.0.0.1:{random_port()}") nodeY = Node("nodeY", connections=["nodeX"], stats_enable=True, stats_port=random_port(), listen=f"ws://127.0.0.1:{random_port()}") random_mesh.add_node(nodeX) random_mesh.add_node(nodeY) nodeX.start() nodeY.start() wait_for(random_mesh.validate_all_node_routes, delay=6, num_sec=30) assert nodeY.ping(1) != "Failed" nodeX.stop() time.sleep(7) assert nodeY.ping(1) == "Failed" nodeX.start() time.sleep(7) wait_for(random_mesh.validate_all_node_routes, delay=6, num_sec=30) assert nodeY.ping(1) != "Failed" nodeY.stop() nodeX.stop()
def test_node_pgid_v1(): """Call ``Node.pgid`` on a not-yet-started node. Assert ``NodeUnavailableError`` is raised. """ node = Node(str(uuid.uuid4())) with pytest.raises(NodeUnavailableError): node.pgid
def test_str_route_mismatch_error(): """Call ``str`` on a ``RouteMismatchError``.""" node = Node(str(uuid.uuid4())) node.start() mesh = Mesh() mesh.add_node(node) err = RouteMismatchError(mesh, (node, )) str(err)
def test_node_pgid_v3(): """Call ``Node.pgid`` on a node that has been started and stopped. Assert ``NodeUnavailableError`` is raised. """ node = Node(str(uuid.uuid4())) node.start() node.stop() with pytest.raises(NodeUnavailableError): node.pgid
def test_websocket_reconnect(random_mesh): nodeX = Node("nodeX", connections=["node1"], stats_enable=True, stats_port=random_port(), listen=f"ws://127.0.0.1:{random_port()}") nodeY = Node("nodeY", connections=["nodeX"], stats_enable=True, stats_port=random_port(), listen=f"ws://127.0.0.1:{random_port()}") random_mesh.add_node(nodeX) random_mesh.add_node(nodeY) nodeX.start() nodeY.start() random_mesh.settle() assert nodeY.ping(1) != "Failed" nodeX.stop() time.sleep(7) assert nodeY.ping(1) == "Failed" nodeX.start() time.sleep(7) random_mesh.settle() assert nodeY.ping(1) != "Failed" nodeY.stop() nodeX.stop()
def test_node_pgid_v2(): """Call ``Node.pgid`` on a started node. Assert an int is returned. """ node = Node(str(uuid.uuid4())) node.start() try: node_pgid = node.pgid assert isinstance(node_pgid, int) finally: node.stop()
def test_add_remove_node(random_mesh): nodeX = Node("nodeX", connections=["controller"], stats_enable=True, stats_port=random_port()) random_mesh.add_node(nodeX) nodeX.start() wait_for(random_mesh.validate_all_node_routes, delay=6, num_sec=30) assert nodeX.ping(1) != "Failed" wait_for(random_mesh.validate_all_node_routes, delay=6, num_sec=30) assert "nodeX" in str(random_mesh.nodes["controller"].get_routes()) assert random_mesh.validate_all_node_routes() nodeX.stop()
def test_add_remove_node(random_mesh): nodeX = Node("nodeX", connections=["controller"], stats_enable=True, stats_port=random_port()) random_mesh.add_node(nodeX) nodeX.start() random_mesh.settle() assert nodeX.ping(1) != "Failed" random_mesh.settle() assert "nodeX" in str(random_mesh.nodes["controller"].get_routes()) random_mesh.validate_routes() nodeX.stop()
def test_alternative_route(tree_mesh): nodeX = Node("nodeX", connections=["node4", "node3"], stats_enable=True, stats_port=random_port()) tree_mesh.add_node(nodeX) nodeX.start() wait_for(tree_mesh.validate_all_node_routes, delay=6, num_sec=30) assert nodeX.ping(1) != "Failed" wait_for(tree_mesh.validate_all_node_routes, delay=6, num_sec=30) assert "nodeX" in str(tree_mesh.nodes["controller"].get_routes()) assert tree_mesh.validate_all_node_routes() tree_mesh.nodes["node3"].stop() time.sleep(7) wait_for(tree_mesh.validate_all_node_routes, num_sec=30) # TODO make ping return quicker if it can't ping then reenable to ensure node3 is dead # assert tree_mesh.nodes['node3'].ping() != "Failed" assert nodeX.ping(1) != "Failed" tree_mesh.nodes["node3"].start() wait_for(tree_mesh.validate_all_node_routes, num_sec=30) tree_mesh.nodes["node4"].stop() time.sleep(7) assert nodeX.ping(1) != "Failed" nodeX.stop()
def test_str_stopped_node_error(): """Call ``str`` on a ``NodeUnavailableError``.""" node = Node(str(uuid.uuid4())) err = NodeUnavailableError(node) str(err)
def test_node_listen_port_v2(): """Call ``Node.listen_port`` on a node for which no port is specified.""" node = Node(str(uuid.uuid4()), listen="receptor://127.0.0.1") assert node.listen_port == 8888