Skip to content
Snippets Groups Projects
Commit d3781001 authored by Damian Johnson's avatar Damian Johnson
Browse files

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-network-port-is-open-on-linux

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.
parent 7901ff11
Branches
Tags
No related merge requests found
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment