Skip to content

Commit

Permalink
try to fix windows
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Oct 23, 2024
1 parent 84e5a17 commit ff90a51
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 11 additions & 4 deletions runtimepy/net/tcp/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ async def create_pair(
peer: type[V] = None,
serve_kwargs: dict[str, _Any] = None,
connect_kwargs: dict[str, _Any] = None,
host: str = "127.0.0.1",
) -> _AsyncIterator[tuple[V, T]]:
"""Create a connection pair."""

Expand All @@ -241,16 +242,22 @@ def callback(conn: V) -> None:
serve_kwargs = {}

server = await stack.enter_async_context(
peer.serve(callback, port=0, backlog=1, **serve_kwargs)
peer.serve(
callback,
host=host,
port=0,
backlog=1,
**serve_kwargs,
)
)

host = server.sockets[0].getsockname()

if connect_kwargs is None:
connect_kwargs = {}

client = await cls.create_connection(
host=host[0], port=host[1], **connect_kwargs
host=host,
port=server.sockets[0].getsockname()[1],
**connect_kwargs,
)
await cond.acquire()

Expand Down
4 changes: 3 additions & 1 deletion tests/net/tcp/test_np_05b.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ async def test_conns(client: Np05bConnection, _: MockNp05b) -> None:
# End the test.
stop_sig.set()

async with MockNp05b.serve(callback=conn_cb, port=0) as server:
async with MockNp05b.serve(
callback=conn_cb, host="127.0.0.1", port=0
) as server:
host = sockname(server.sockets[0])
conn = await Np05bConnection.create_connection(
host=host.name, port=host.port
Expand Down

0 comments on commit ff90a51

Please sign in to comment.