[tor-commits] [stem/master] Reduce remaining sleeps

atagar at torproject.org atagar at torproject.org
Sun Feb 12 05:52:41 UTC 2017


commit 3bdc1d1a9363a1c039f0ea47a1f93a2a8de864b3
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Feb 8 10:29:36 2017 -0800

    Reduce remaining sleeps
    
    Easy drop of our integ runtime from 1-3s simply by reducing the sleeps we do
    (they can be arbitrarily short, our tests don't care).
---
 test/integ/control/base_controller.py |  2 +-
 test/integ/control/controller.py      |  2 +-
 test/integ/process.py                 | 12 ++++++++----
 test/integ/socket/control_socket.py   |  4 ++--
 test/integ/util/system.py             |  4 ++--
 5 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/test/integ/control/base_controller.py b/test/integ/control/base_controller.py
index 51576a8..dc2e478 100644
--- a/test/integ/control/base_controller.py
+++ b/test/integ/control/base_controller.py
@@ -242,7 +242,7 @@ class TestBaseController(unittest.TestCase):
 
       controller.add_status_listener(state_observer.listener, True)
       controller.close()
-      time.sleep(0.1)  # not much work going on so this doesn't need to be much
+      time.sleep(0.001)  # not much work going on so this doesn't need to be much
       self.assertEqual(controller, state_observer.controller)
       self.assertEqual(stem.control.State.CLOSED, state_observer.state)
       self.assertTrue(state_observer.timestamp <= time.time())
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index 0d17b0b..a1f155b 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -111,7 +111,7 @@ class TestController(unittest.TestCase):
         if (time.time() - before) > 2:
           self.fail("We've waited a couple seconds for SIGHUP to generate an event, but it didn't come")
 
-        time.sleep(0.1)
+        time.sleep(0.001)
 
       after = time.time()
 
diff --git a/test/integ/process.py b/test/integ/process.py
index b082d0b..19d6750 100644
--- a/test/integ/process.py
+++ b/test/integ/process.py
@@ -421,11 +421,13 @@ class TestProcess(unittest.TestCase):
     #
     #   https://trac.torproject.org/projects/tor/ticket/21281
 
-    for seconds_waited in range(30):
+    start_time = time.time()
+
+    while time.time() - start_time < 30:
       if tor_process.poll() == 0:
         return  # tor exited
 
-      time.sleep(1)
+      time.sleep(0.01)
 
     self.fail("tor didn't quit after the process that owned it terminated")
 
@@ -455,11 +457,13 @@ class TestProcess(unittest.TestCase):
     controller.close()
 
     # give tor a few seconds to quit
-    for seconds_waited in range(5):
+    start_time = time.time()
+
+    while time.time() - start_time < 5:
       if tor_process.poll() == 0:
         return  # tor exited
 
-      time.sleep(1)
+      time.sleep(0.01)
 
     self.fail("tor didn't quit after the controller that owned it disconnected")
 
diff --git a/test/integ/socket/control_socket.py b/test/integ/socket/control_socket.py
index 83851be..a1e603b 100644
--- a/test/integ/socket/control_socket.py
+++ b/test/integ/socket/control_socket.py
@@ -38,7 +38,7 @@ class TestControlSocket(unittest.TestCase):
 
       # connection time should be absolute (shouldn't change as time goes on)
 
-      time.sleep(0.1)
+      time.sleep(0.001)
       self.assertEqual(connection_time, control_socket.connection_time())
 
       # should change to the disconnection time if we detactch
@@ -49,7 +49,7 @@ class TestControlSocket(unittest.TestCase):
 
       # then change again if we reconnect
 
-      time.sleep(0.1)
+      time.sleep(0.001)
       control_socket.connect()
       reconnection_time = control_socket.connection_time()
       self.assertTrue(disconnection_time < reconnection_time <= time.time())
diff --git a/test/integ/util/system.py b/test/integ/util/system.py
index 7933492..dd301f9 100644
--- a/test/integ/util/system.py
+++ b/test/integ/util/system.py
@@ -569,8 +569,8 @@ class TestSystem(unittest.TestCase):
     """
 
     initial = stem.util.system.SYSTEM_CALL_TIME
-    stem.util.system.call('sleep 0.5')
-    self.assertTrue(stem.util.system.SYSTEM_CALL_TIME - initial > 0.4)
+    stem.util.system.call('sleep 0.005')
+    self.assertTrue(stem.util.system.SYSTEM_CALL_TIME - initial > 0.004)
 
   def test_set_process_name(self):
     """





More information about the tor-commits mailing list