Skip to content

Commit 20acb2c

Browse files
Merge pull request #139 from Ichimonji10/test-ports
Add test for invalid listen scheme Reviewed-by: https://github.com/apps/ansible-zuul
2 parents a709699 + 0f004dc commit 20acb2c

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

Diff for: poetry.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ receptor-affinity = { git = "https://github.com/project-receptor/affinity.git" }
3030
tox = "^3.14.5"
3131
yamllint = "^1.20.0"
3232
black = "^19.10b0"
33+
psutil = "^5.7.0"
3334

3435
[tool.poetry.scripts]
3536
receptor = 'receptor.__main__:main'

Diff for: test/perf/test_ports.py

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"""Test port binding logic."""
2+
from uuid import uuid4
3+
4+
import psutil
5+
import pytest
6+
from receptor_affinity import utils
7+
from receptor_affinity.exceptions import NodeUnavailableError
8+
from receptor_affinity.mesh import Node
9+
10+
11+
def test_invalid_listen_scheme():
12+
"""Start a node, and give it a listen address with an invalid scheme.
13+
14+
The node should fail to start. See `receptor #93`_.
15+
16+
.. NOTE:: This test should be extended to check that a traceback isn't printed to stdout or
17+
stderr.
18+
19+
.. _receptor #93: https://github.com/project-receptor/receptor/issues/93
20+
"""
21+
node = Node(str(uuid4()), listen=f'harglebargle://127.0.0.1:{utils.random_port()}')
22+
with pytest.raises(NodeUnavailableError):
23+
node.start()
24+
25+
26+
def test_listen_fragment():
27+
"""Start a node, and give it a listen address with a fragment.
28+
29+
The node should fail to start. See `receptor #153`_.
30+
31+
.. _receptor #153: https://github.com/project-receptor/receptor/issues/153
32+
"""
33+
node = Node(str(uuid4()), listen=f'receptor://127.0.0.1:{utils.random_port()}#frag')
34+
with pytest.raises(NodeUnavailableError):
35+
node.start()
36+
37+
38+
def test_listen_path():
39+
"""Start a node, and give it a listen address with a path.
40+
41+
The node should fail to start. See `receptor #153`_.
42+
43+
.. _receptor #153: https://github.com/project-receptor/receptor/issues/153
44+
"""
45+
node = Node(str(uuid4()), listen=f'receptor://127.0.0.1:{utils.random_port()}/path')
46+
with pytest.raises(NodeUnavailableError):
47+
node.start()
48+
49+
50+
def test_listen_query():
51+
"""Start a node, and give it a listen address with a query.
52+
53+
The node should fail to start. See `receptor #153`_.
54+
55+
.. _receptor #153: https://github.com/project-receptor/receptor/issues/153
56+
"""
57+
node = Node(str(uuid4()), listen=f'receptor://127.0.0.1:{utils.random_port()}?key=val')
58+
with pytest.raises(NodeUnavailableError):
59+
node.start()
60+
61+
62+
def test_no_port_given():
63+
"""Start a node, and don't specify a port on which to listen.
64+
65+
Assert that it listens on port 8888. Older versions of receptor would listen on a random port.
66+
See: `receptor #138`_.
67+
68+
.. _receptor #138: https://github.com/project-receptor/receptor/issues/138
69+
"""
70+
node = Node(str(uuid4()), listen=f'receptor://127.0.0.1')
71+
node.start()
72+
try:
73+
conns = psutil.Process(node.pid).connections()
74+
assert len(conns) == 1
75+
assert conns[0].laddr.port == 8888
76+
finally:
77+
node.stop()

0 commit comments

Comments
 (0)