[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Make test_attach_stream more robust



commit d70e98ab0c58aa5a209b24394852ecb7ae39e563
Author: Ravi Chandra Padmala <neenaoffline@xxxxxxxxx>
Date:   Wed Dec 26 14:44:38 2012 +0530

    Make test_attach_stream more robust
---
 test/integ/control/controller.py |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index c77b7cb..e950ff8 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -732,14 +732,23 @@ class TestController(unittest.TestCase):
     with runner.get_tor_controller() as controller:
       controller.set_conf("__LeaveStreamsUnattached", "1")
       socksport = controller.get_conf("SocksPort")
-      circuits_3hop = [c.id for c in controller.get_circuits() if len(c.path) == 3]
-      self.assertTrue(len(circuits_3hop) > 0)
-      circuit_id = circuits_3hop[0]
+      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 = [c for c in controller.get_circuits() if c.id == circuit_id]



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits