[tor-commits] [stem/master] Move test's ownership connection into runner

atagar at torproject.org atagar at torproject.org
Sun Jun 18 17:44:12 UTC 2017


commit dd9252f716ba54d556f032611b6c1509d414b0a1
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Jun 17 13:24:35 2017 -0700

    Move test's ownership connection into runner
    
    To ensure our integ test's tor instance is promptly terminated when the tests
    end we establish ownership over the process. As such we need to ensure our
    first controller connection lasts until we're all done.
    
    Moving this into the runner so our run_tests.py don't need to worry about it.
---
 run_tests.py   |  8 --------
 test/runner.py | 16 ++++++++++++++--
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index 9701178..bf5a191 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -278,18 +278,10 @@ def main():
 
         println('Running tests...\n', STATUS)
 
-        owner = None
-
-        if integ_runner.is_accessible():
-          owner = integ_runner.get_tor_controller(True)  # controller to own our main Tor process
-
         for test_class in get_integ_tests(args.specific_test):
           run_result = _run_test(args, test_class, output_filters, logging_buffer)
           skipped_tests += len(getattr(run_result, 'skipped', []))
 
-        if owner:
-          owner.close()
-
         # We should have joined on all threads. If not then that indicates a
         # leak that could both likely be a bug and disrupt further targets.
 
diff --git a/test/runner.py b/test/runner.py
index b40ca19..14795ce 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -163,6 +163,12 @@ class Runner(object):
 
     self._original_recv_message = None
 
+    # The first controller to attach takes ownership so tor will promptly
+    # terminate if the tests do. As such we need to ensure that first
+    # connection is our runner's.
+
+    self._owner_controller = None
+
   def start(self, attribute_targets, tor_cmd, extra_torrc_opts):
     """
     Makes temporary testing resources and starts tor, blocking until it
@@ -234,9 +240,11 @@ class Runner(object):
 
           stem.socket.recv_message = _chroot_recv_message
 
-        # revert our cwd back to normal
+        if self.is_accessible():
+          self._owner_controller = self.get_tor_controller(True)
+
         if test.Target.RELATIVE in self.attribute_targets:
-          os.chdir(original_cwd)
+          os.chdir(original_cwd)  # revert our cwd back to normal
       except OSError as exc:
         raise exc
 
@@ -248,6 +256,10 @@ class Runner(object):
     with self._runner_lock:
       println('Shutting down tor... ', STATUS, NO_NL)
 
+      if self._owner_controller:
+        self._owner_controller.close()
+        self._owner_controller = None
+
       if self._tor_process:
         # if the tor process has stopped on its own then the following raises
         # an OSError ([Errno 3] No such process)



More information about the tor-commits mailing list