commit d37810010f4f587dbb848e9ac69ab9f9472e47dd Author: Damian Johnson atagar@torproject.org Date: Fri Jul 14 12:40:47 2017 -0700
Ensure port used by process tests is unused
When running in a loop catalyst occasionally runs into...
OSError: Process terminated: Failed to bind one of the listener ports. https://trac.torproject.org/projects/tor/ticket/22902
First guess is that maybe multiple tests pick the same random port, or something that's coincidently being used by the system. Tried to use socket's connect_ex() for this...
https://stackoverflow.com/questions/19196105/python-how-to-check-if-a-networ...
But doing so causes exactly the binding failures we're attempting to avoid (even with a sleep after closing). Weird. Just checking for process instead. --- test/integ/process.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/test/integ/process.py b/test/integ/process.py index 70f414c..dea0b4c 100644 --- a/test/integ/process.py +++ b/test/integ/process.py @@ -2,6 +2,8 @@ Tests the stem.process functions with various use cases. """
+from __future__ import absolute_import + import binascii import hashlib import os @@ -45,7 +47,11 @@ DataDirectory %s
def random_port(): - return str(random.randint(1024, 65535)) + while True: + port = random.randint(1024, 65535) + + if stem.util.system.pid_by_port(port) is None: + return str(port)
@contextmanager @@ -552,8 +558,8 @@ class TestProcess(unittest.TestCase): except OSError: runtime = time.time() - start_time
- if not (runtime > 0.05 and runtime < 1): - raise AssertionError('Test should have taken 0.05-1 seconds, took %0.1f instead' % runtime) + if not (runtime > 0.05 and runtime < 3): + raise AssertionError('Test should have taken 0.05-3 seconds, took %0.1f instead' % runtime)
@asynchronous def test_take_ownership_via_pid(tor_cmd):
tor-commits@lists.torproject.org