0001-tests-improve-search-of-a-free-TCP-port-72645.patch
hobo/test_utils.py | ||
---|---|---|
1 | 1 |
import os |
2 |
import socket |
|
3 |
import struct |
|
4 |
from contextlib import closing |
|
2 | 5 | |
3 | 6 | |
4 | 7 |
def get_safe_db_name(): |
... | ... | |
20 | 23 |
# for us at a later point |
21 | 24 |
parts.append(os.environ.get('TOX_ENV_NAME')) |
22 | 25 |
return '_'.join(parts) |
26 | ||
27 | ||
28 |
def find_free_port(): |
|
29 |
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s: |
|
30 |
s.bind(('', 0)) |
|
31 |
s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", 1, 0)) |
|
32 |
return s.getsockname()[1] |
tests/test_emails.py | ||
---|---|---|
16 | 16 | |
17 | 17 |
from hobo.emails.validators import validate_email_address |
18 | 18 |
from hobo.environment.models import Variable |
19 |
from hobo.test_utils import find_free_port |
|
19 | 20 | |
20 | 21 | |
21 | 22 |
@pytest.fixture |
22 | 23 |
def port_available(): |
23 |
errno = 0 |
|
24 |
while not errno: |
|
25 |
port = random.randint(49152, 65534) |
|
26 |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
27 |
errno = sock.connect_ex(('127.0.0.1', port)) |
|
28 |
sock.close() |
|
29 |
return port |
|
24 |
return find_free_port() |
|
30 | 25 | |
31 | 26 | |
32 | 27 |
@pytest.fixture |
33 |
- |