Skip to content

Commit fbc9325

Browse files
committed
Start a very basic ipc-server unit test suite
For now it just boots a server, parametrized over all tpt-protos, sin any actor runtime bootup. Obvi the future todo is ensuring it all works with a client connecting via the equivalent lowlevel `.ipc._chan._connect_chan()` API(s).
1 parent 3cd2229 commit fbc9325

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

tests/ipc/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'''
2+
`tractor.ipc` subsystem(s)/unit testing suites.
3+
4+
'''

tests/ipc/test_server.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
'''
2+
High-level `.ipc._server` unit tests.
3+
4+
'''
5+
from __future__ import annotations
6+
7+
import pytest
8+
import trio
9+
from tractor import (
10+
devx,
11+
ipc,
12+
log,
13+
)
14+
from tractor._testing.addr import (
15+
get_rando_addr,
16+
)
17+
# TODO, use/check-roundtripping with some of these wrapper types?
18+
#
19+
# from .._addr import Address
20+
# from ._chan import Channel
21+
# from ._transport import MsgTransport
22+
# from ._uds import UDSAddress
23+
# from ._tcp import TCPAddress
24+
25+
26+
@pytest.mark.parametrize(
27+
'_tpt_proto',
28+
['uds', 'tcp']
29+
)
30+
def test_basic_ipc_server(
31+
_tpt_proto: str,
32+
debug_mode: bool,
33+
loglevel: str,
34+
):
35+
36+
# so we see the socket-listener reporting on console
37+
log.get_console_log("INFO")
38+
39+
rando_addr: tuple = get_rando_addr(
40+
tpt_proto=_tpt_proto,
41+
)
42+
async def main():
43+
async with ipc._server.open_ipc_server() as server:
44+
45+
assert (
46+
server._parent_tn
47+
and
48+
server._parent_tn is server._stream_handler_tn
49+
)
50+
assert server._no_more_peers.is_set()
51+
52+
eps: list[ipc.IPCEndpoint] = await server.listen_on(
53+
accept_addrs=[rando_addr],
54+
stream_handler_nursery=None,
55+
)
56+
assert (
57+
len(eps) == 1
58+
and
59+
(ep := eps[0])._listener
60+
and
61+
not ep.peer_tpts
62+
)
63+
64+
server._parent_tn.cancel_scope.cancel()
65+
66+
# !TODO! actually make a bg-task connection from a client
67+
# using `ipc._chan._connect_chan()`
68+
69+
with devx.maybe_open_crash_handler(
70+
pdb=debug_mode,
71+
):
72+
trio.run(main)

0 commit comments

Comments
 (0)