commit 11ef43c64479af8a9fe50b01e980d02234671977 Author: Damian Johnson atagar@torproject.org Date: Sun Dec 30 16:32:16 2012 -0800
Reverting __LeaveStreamsUnattached when test fails
Putting the cleanup activity for test_attachstream() into a finally block so we still do it when the test fails. We also forgot to remove the handle_circ listener. --- test/integ/control/controller.py | 58 +++++++++++++++++++------------------ 1 files changed, 30 insertions(+), 28 deletions(-)
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py index 40c0f8c..f6fd147 100644 --- a/test/integ/control/controller.py +++ b/test/integ/control/controller.py @@ -722,42 +722,44 @@ class TestController(unittest.TestCase): if count > 10: break
def test_attachstream(self): - if test.runner.require_control(self): return elif test.runner.require_online(self): return
- runner = test.runner.get_runner() + def handle_streamcreated(stream): + if stream.status == "NEW": + controller.attach_stream(int(stream.id), int(circuit_id))
- with runner.get_tor_controller() as controller: + circ_status_q = Queue() + def handle_circ(circuit): + circ_status_q.put(circuit) + + with test.runner.get_runner().get_tor_controller() as controller: controller.set_conf("__LeaveStreamsUnattached", "1") - socksport = int(controller.get_conf('SocksListenAddress').rsplit(':', 1)[1]) - circ_status, circ_status_q = "", Queue() - - def handle_circ(circuit): - circ_status_q.put(circuit) - - def handle_streamcreated(stream): - if stream.status == "NEW": - controller.attach_stream(int(stream.id), int(circuit_id)) - controller.add_event_listener(handle_circ, stem.control.EventType.CIRC) - while circ_status != "BUILT": - circuit_id = controller.new_circuit() - while not circ_status in ("BUILT", "FAILED"): - circ_event = circ_status_q.get() - if circ_event.id == circuit_id: - circ_status = circ_event.status - controller.add_event_listener(handle_streamcreated, stem.control.EventType.STREAM) - ip = test.util.external_ip('127.0.0.1', socksport) - exit_circuit = controller.get_circuit(circuit_id) - self.assertTrue(exit_circuit) - exit_ip = controller.get_network_status(exit_circuit.path[2][0]).address - - self.assertEquals(exit_ip, ip)
- controller.remove_event_listener(handle_streamcreated) - controller.reset_conf("__LeaveStreamsUnattached") + try: + socksport = int(controller.get_conf('SocksListenAddress').rsplit(':', 1)[1]) + circ_status = "" + + while circ_status != "BUILT": + circuit_id = controller.new_circuit() + + while not circ_status in ("BUILT", "FAILED"): + circ_event = circ_status_q.get() + if circ_event.id == circuit_id: + circ_status = circ_event.status + + ip = test.util.external_ip('127.0.0.1', socksport) + exit_circuit = controller.get_circuit(circuit_id) + self.assertTrue(exit_circuit) + exit_ip = controller.get_network_status(exit_circuit.path[2][0]).address + + self.assertEquals(exit_ip, ip) + finally: + controller.remove_event_listener(handle_circ) + controller.remove_event_listener(handle_streamcreated) + controller.reset_conf("__LeaveStreamsUnattached")
def test_get_circuits(self): """