[tor-commits] [stem/master] Integ tests for launch_tor

atagar at torproject.org atagar at torproject.org
Fri May 11 16:31:26 UTC 2012


commit bfb3973049c72a9bd6de951566417eca7e132e70
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri May 11 09:28:51 2012 -0700

    Integ tests for launch_tor
    
    I've been leaving launch_tor untested because it was exercised in order to run
    the integ tests and any tests involving it would take a long time, on the order
    of a dozen seconds! Hey, it's a long time when you run this as often as I do...
    
    It's an important function and has more options than what's exercised for
    running integ tests so adding some tests for it.
---
 run_tests.py           |    2 +
 test/integ/__init__.py |    2 +-
 test/integ/process.py  |   65 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 1 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index 9ee6042..818bfb8 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -37,6 +37,7 @@ import test.integ.descriptor.reader
 import test.integ.descriptor.server_descriptor
 import test.integ.util.conf
 import test.integ.util.system
+import test.integ.process
 import test.integ.version
 
 import stem.util.conf
@@ -106,6 +107,7 @@ INTEG_TESTS = (
   test.integ.descriptor.reader.TestDescriptorReader,
   test.integ.descriptor.server_descriptor.TestServerDescriptor,
   test.integ.version.TestVersion,
+  test.integ.process.TestProcess,
   test.integ.socket.control_socket.TestControlSocket,
   test.integ.socket.control_message.TestControlMessage,
   test.integ.connection.protocolinfo.TestProtocolInfo,
diff --git a/test/integ/__init__.py b/test/integ/__init__.py
index a50d3f3..a9bb9ef 100644
--- a/test/integ/__init__.py
+++ b/test/integ/__init__.py
@@ -2,5 +2,5 @@
 Integration tests for the stem library.
 """
 
-__all__ = ["connection", "control", "descriptor", "socket", "util", "version"]
+__all__ = ["connection", "control", "descriptor", "process", "socket", "util", "version"]
 
diff --git a/test/integ/process.py b/test/integ/process.py
new file mode 100644
index 0000000..b03fb27
--- /dev/null
+++ b/test/integ/process.py
@@ -0,0 +1,65 @@
+"""
+Tests the stem.process functions with various use cases.
+"""
+
+import time
+import unittest
+
+import stem.socket
+import stem.process
+import test.runner
+
+# Tests are target independent. Only run once even if there's multiple targets.
+
+RAN_TESTS = []
+
+class TestProcess(unittest.TestCase):
+  def test_launch_tor_options(self):
+    """
+    Runs launch_tor with options specified via the commandline rather than the
+    torrc.
+    """
+    
+    test_name = 'test_launch_tor_options'
+    if test_name in RAN_TESTS: self.skipTest("(already ran)")
+    
+    # Launch tor without a torrc, but with a control port. Confirms that this
+    # works by checking that we're still able to access the new instance.
+    
+    tor_process = stem.process.launch_tor(
+      options = {'SocksPort': '2777', 'ControlPort': '2778'},
+      torrc_path = stem.process.NO_TORRC,
+      completion_percent = 5
+    )
+    
+    control_socket = None
+    try:
+      control_socket = stem.socket.ControlPort(control_port = 2778)
+      runner = test.runner.get_runner()
+      stem.connection.authenticate(control_socket, chroot_path = runner.get_chroot())
+      
+      # exercises the socket
+      control_socket.send("GETINFO version")
+      version_response = control_socket.recv()
+      self.assertEquals("version=%s\nOK" % runner.get_tor_version(), str(version_response))
+    finally:
+      if control_socket: control_socket.close()
+      tor_process.kill()
+    
+    RAN_TESTS.append(test_name)
+  
+  def test_launch_tor_with_timeout(self):
+    """
+    Runs launch_tor where it times out before completing.
+    """
+    
+    test_name = 'test_launch_tor_with_timeout'
+    if test_name in RAN_TESTS: self.skipTest("(already ran)")
+    
+    start_time = time.time()
+    self.assertRaises(OSError, stem.process.launch_tor, "tor", {'SocksPort': '2777'}, stem.process.NO_TORRC, 100, None, 2)
+    runtime = time.time() - start_time
+    self.assertTrue(runtime > 2 and runtime < 3)
+    
+    RAN_TESTS.append(test_name)
+



More information about the tor-commits mailing list