From 43024c6735391e3030bfbb0f170b59d00b788728 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 13 Apr 2014 13:24:17 +0100 Subject: Lots of better test stuff --- lib/chutney/Testing.py | 27 ++++++++++++++++++++------- networks/hs-dual-intro-fail-3 | 3 +++ networks/hs-intro-fail-2 | 3 +++ networks/hs-intro-fail-3 | 8 +++----- networks/hs-intro-select-2 | 8 +++----- networks/hs-start-3 | 8 +++----- networks/hs-stop-3 | 8 +++----- networks/hs-tripple-intro-fail-3 | 8 +++----- networks/hs_instance_start.py | 9 +++++++-- networks/hs_instance_stop.py | 23 +++++++++++++++-------- networks/hs_intro_fail.py | 4 ++-- networks/hs_intro_selection.py | 16 ++++++++++------ 12 files changed, 75 insertions(+), 50 deletions(-) diff --git a/lib/chutney/Testing.py b/lib/chutney/Testing.py index 8b1b356..341f519 100644 --- a/lib/chutney/Testing.py +++ b/lib/chutney/Testing.py @@ -240,14 +240,23 @@ def create_hidden_service(nodes): isLeaf = True numberRequests = 0 - def __init__(self, siteNum): + def __init__(self, siteNum, port): self.siteNum = siteNum + self.port = port def render_GET(self, request): self.numberRequests += 1 request.setHeader("content-type", "text/plain") return str(self.siteNum) + def listen(self): + site = server.Site(self) + self.s = reactor.listenTCP(self.port, site) + + def stopListening(self): + self.s.stopListening() + + base_port = 10080 for i in range(nodes): @@ -261,10 +270,7 @@ def create_hidden_service(nodes): ) hs_nodes.append(node) - site = server.Site(Site(i)) - - s = reactor.listenTCP(port, site) - hs_servers.append(s) + hs_servers.append(Site(i, port)) port += 1 @@ -285,13 +291,20 @@ def connection_test(client_nodes, expected_nodes): test_pass = True + nodes_detected = 0 + for node, responses in sorted(responses.items()): logging.info(node + ": " + str(responses)) - if responses == 0: - test_pass = False + if responses != 0: + nodes_detected += 1 + + if nodes_detected != expected_nodes: + test_pass = False if test_pass: logging.info("Test PASS") else: logging.info("Test FAIL") + + return test_pass diff --git a/networks/hs-dual-intro-fail-3 b/networks/hs-dual-intro-fail-3 index 9be8479..e467255 100644 --- a/networks/hs-dual-intro-fail-3 +++ b/networks/hs-dual-intro-fail-3 @@ -25,6 +25,9 @@ network.add(Node.create(30, { })) def start(): + for server in hs_servers: + server.listen() + results = hs_fail_test(network, failures=2) for server in hs_servers: diff --git a/networks/hs-intro-fail-2 b/networks/hs-intro-fail-2 index ae0a35b..9b5cf2a 100644 --- a/networks/hs-intro-fail-2 +++ b/networks/hs-intro-fail-2 @@ -25,6 +25,9 @@ network.add(Node.create(10, { })) def start(): + for server in hs_servers: + server.listen() + results = hs_fail_test(network) for server in hs_servers: diff --git a/networks/hs-intro-fail-3 b/networks/hs-intro-fail-3 index 4835b0c..52192a5 100644 --- a/networks/hs-intro-fail-3 +++ b/networks/hs-intro-fail-3 @@ -25,6 +25,9 @@ network.add(Node.create(10, { })) def start(): + for server in hs_servers: + server.listen() + results = hs_fail_test(network) for server in hs_servers: @@ -32,10 +35,5 @@ def start(): network.stop() - if results: - logging.info("hs-intro-fail-3 PASS") - else: - logging.info("hs-intro-fail-3 FAIL") - return results diff --git a/networks/hs-intro-select-2 b/networks/hs-intro-select-2 index e477a00..1881bb6 100644 --- a/networks/hs-intro-select-2 +++ b/networks/hs-intro-select-2 @@ -25,6 +25,9 @@ network.add(Node.create(10, { })) def start(): + for server in hs_servers: + server.listen() + results = hs_select_test(network) for server in hs_servers: @@ -32,9 +35,4 @@ def start(): network.stop() - if results: - logging.info("hs-intro-select-2 PASS") - else: - logging.info("hs-intro-select-2 FAIL") - return results diff --git a/networks/hs-start-3 b/networks/hs-start-3 index 4fead95..e01a7a5 100644 --- a/networks/hs-start-3 +++ b/networks/hs-start-3 @@ -25,6 +25,9 @@ network.add(Node.create(10, { })) def start(): + for server in hs_servers: + server.listen() + results = hs_instance_start(network) for server in hs_servers: @@ -32,9 +35,4 @@ def start(): network.stop() - if results: - logging.info("hs-start-3 PASS") - else: - logging.info("hs-start-3 FAIL") - return results diff --git a/networks/hs-stop-3 b/networks/hs-stop-3 index 7d30f40..8d4f372 100644 --- a/networks/hs-stop-3 +++ b/networks/hs-stop-3 @@ -25,6 +25,9 @@ network.add(Node.create(10, { })) def start(): + for server in hs_servers: + server.listen() + results = hs_instance_stop(network) for server in hs_servers: @@ -32,9 +35,4 @@ def start(): network.stop() - if results: - logging.info("hs-stop-3 PASS") - else: - logging.info("hs-stop-3 FAIL") - return results diff --git a/networks/hs-tripple-intro-fail-3 b/networks/hs-tripple-intro-fail-3 index fedfc44..54d3d0a 100644 --- a/networks/hs-tripple-intro-fail-3 +++ b/networks/hs-tripple-intro-fail-3 @@ -25,6 +25,9 @@ network.add(Node.create(30, { })) def start(): + for server in hs_servers: + server.listen() + results = hs_fail_test(network, failures=3) for server in hs_servers: @@ -32,10 +35,5 @@ def start(): network.stop() - if results: - logging.info("hs-tripple-fail-3 PASS") - else: - logging.info("hs-tripple-fail-3 FAIL") - return results diff --git a/networks/hs_instance_start.py b/networks/hs_instance_start.py index 38282de..19cb3ad 100644 --- a/networks/hs_instance_start.py +++ b/networks/hs_instance_start.py @@ -4,6 +4,8 @@ from chutney.TorNet import * from stem.control import EventType def hs_instance_start(network): + result = True + hs_nodes = network.get("h") clients = network.get("c") @@ -57,6 +59,9 @@ def hs_instance_start(network): for c_group in range(i + 1): logging.info("Testing with the %d client group" % c_group) - connection_test(client_groups[c_group], i + 1) + expected_nodes = min(c_group, i) + result &= connection_test(client_groups[c_group], expected_nodes) + + result &= check_same_intro_points() - check_same_intro_points() + return result diff --git a/networks/hs_instance_stop.py b/networks/hs_instance_stop.py index f3ca787..01ed865 100644 --- a/networks/hs_instance_stop.py +++ b/networks/hs_instance_stop.py @@ -6,6 +6,8 @@ from stem.control import EventType import time def hs_instance_stop(network): + result = True + hs_nodes = network.get("h") clients = network.get("c") @@ -35,6 +37,7 @@ def hs_instance_stop(network): logging.info("There are %d nodes to start" % len(hs_nodes)) + # Start each node, one by one for i, hs_node in enumerate(hs_nodes): logging.info("Starting node %d" % i) @@ -57,14 +60,15 @@ def hs_instance_stop(network): hs_node.getStemController().remove_event_listener(hs_node_listener) # Now begin testing + logging.info("Testing with the %d client group" % i) + result &= connection_test(client_groups[i], i + 1) - for c_group in range(i + 1): - logging.info("Testing with the %d client group" % c_group) - connection_test(client_groups[c_group], i + 1) - - check_same_intro_points() + result &= check_same_intro_points() - for i, hs_node in reversed(list(enumerate(hs_nodes))): + # Stop all but the first node in turn, checking that all currently active + # nodes are reachable, and that all active nodes have the same introduction + # points + for i, hs_node in reversed(list(enumerate(hs_nodes))[1:]): logging.info("Stopping node %d" % i) hs_node.getController().stop() @@ -75,6 +79,9 @@ def hs_instance_stop(network): for c_group in range(len(hs_nodes)): logging.info("Testing with the %d client group" % c_group) - connection_test(client_groups[c_group], i + 1) + expected_nodes = min(c_group, i) + result &= connection_test(client_groups[c_group], expected_nodes) + + result &= check_same_intro_points() - check_same_intro_points() + return result diff --git a/networks/hs_intro_fail.py b/networks/hs_intro_fail.py index 90c7f48..4850026 100644 --- a/networks/hs_intro_fail.py +++ b/networks/hs_intro_fail.py @@ -58,7 +58,7 @@ def hs_fail_test(network, failures=1): # Now begin testing - connection_test(network.get("c"), len(hs_nodes)) + result &= connection_test(network.get("c"), len(hs_nodes)) time.sleep(5) @@ -105,6 +105,6 @@ def hs_fail_test(network, failures=1): result &= check_same_intro_points() - connection_test(network.get("c"), len(hs_nodes)) + result &= connection_test(network.get("c"), len(hs_nodes)) return result diff --git a/networks/hs_intro_selection.py b/networks/hs_intro_selection.py index 99b73d8..1ed351a 100644 --- a/networks/hs_intro_selection.py +++ b/networks/hs_intro_selection.py @@ -4,6 +4,8 @@ from chutney.TorNet import * from stem.control import EventType def hs_select_test(network, failures=1): + result = True + hs_nodes = network.get("h") initial_nodes = network.get("a") + network.get("r") + network.get("c") + hs_nodes[:1] @@ -57,7 +59,7 @@ def hs_select_test(network, failures=1): # Now begin testing - connection_test(network.get("c"), len(hs_nodes)) + result &= connection_test(network.get("c"), len(hs_nodes)) time.sleep(5) @@ -65,8 +67,8 @@ def hs_select_test(network, failures=1): next_intro_points = get_next_intro_points() - print("Predicted new introduction points") - print(next_intro_points) + logging.info("Predicted new introduction points") + logging.info(next_intro_points) fingerprint = next_intro_points[0][0] node = nodes_by_fingerprint[fingerprint] @@ -77,7 +79,7 @@ def hs_select_test(network, failures=1): time.sleep(10) - check_same_intro_points() + result &= check_same_intro_points() logging.info("About to stop %d introduction points" % failures) @@ -120,6 +122,8 @@ def hs_select_test(network, failures=1): else: logging.info("All did not change") - check_same_intro_points() + result &= check_same_intro_points() + + result &= connection_test(network.get("c"), len(hs_nodes)) - connection_test(network.get("c"), len(hs_nodes)) + return result -- cgit v1.2.3