[tor-commits] [stem/master] test_no_orphaned_process failed if no tor binary was on the path

atagar at torproject.org atagar at torproject.org
Wed Jul 12 16:41:38 UTC 2017


commit 7a09b7706105f3173748f8e5257f4152107f5cc8
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Jul 12 09:30:54 2017 -0700

    test_no_orphaned_process failed if no tor binary was on the path
    
    Oops, we forgot to pass the tor path into one of the process tests...
    
      https://trac.torproject.org/projects/tor/ticket/22894
---
 test/integ/process.py | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/test/integ/process.py b/test/integ/process.py
index a7e2bc3..70f414c 100644
--- a/test/integ/process.py
+++ b/test/integ/process.py
@@ -258,28 +258,31 @@ class TestProcess(unittest.TestCase):
     elif 'UseBridges' not in output or 'SocksPort' not in output:
       raise AssertionError("'tor --list-torrc-options' didn't have options we expect")
 
-  @test.require.command('sleep')
-  @patch('re.compile', Mock(side_effect = KeyboardInterrupt('nope')))
-  def test_no_orphaned_process(self):
+  @asynchronous
+  def test_no_orphaned_process(tor_cmd):
     """
     Check that when an exception arises in the middle of spawning tor that we
     don't leave a lingering process.
     """
 
-    # We don't need to actually run tor for this test. Rather, any process will
-    # do the trick. Picking sleep so this'll clean itself up if our test fails.
+    if not stem.util.system.is_available('sleep'):
+      skip('(sleep unavailable)')
 
-    mock_tor_process = subprocess.Popen(['sleep', '60'])
+    with patch('re.compile', Mock(side_effect = KeyboardInterrupt('nope'))):
+      # We don't need to actually run tor for this test. Rather, any process will
+      # do the trick. Picking sleep so this'll clean itself up if our test fails.
 
-    with patch('subprocess.Popen', Mock(return_value = mock_tor_process)):
-      try:
-        stem.process.launch_tor()
-        self.fail("tor shoudn't have started")
-      except KeyboardInterrupt as exc:
-        if os.path.exists('/proc/%s' % mock_tor_process.pid):
-          self.fail('launch_tor() left a lingering tor process')
+      mock_tor_process = subprocess.Popen(['sleep', '60'])
+
+      with patch('subprocess.Popen', Mock(return_value = mock_tor_process)):
+        try:
+          stem.process.launch_tor(tor_cmd)
+          raise AssertionError("tor shoudn't have started")
+        except KeyboardInterrupt as exc:
+          if os.path.exists('/proc/%s' % mock_tor_process.pid):
+            raise AssertionError('launch_tor() left a lingering tor process')
 
-        self.assertEqual('nope', str(exc))
+          assert_equal('nope', str(exc))
 
   @asynchronous
   def test_torrc_arguments(tor_cmd):



More information about the tor-commits mailing list