Skip to content

Commit b3ca75c

Browse files
committed
Add a test for AsyncIPCProvider writes ending with newline delimiter
1 parent 0471ac7 commit b3ca75c

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

tests/core/providers/test_async_ipc_provider.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
Thread,
99
)
1010
import time
11+
from unittest.mock import (
12+
AsyncMock,
13+
Mock,
14+
)
1115

1216
from websockets import (
1317
ConnectionClosed,
@@ -43,7 +47,7 @@
4347

4448
TWENTY_MB = 20 * 1024 * 1024
4549
SIZED_MSG_START = b'{"id": 0, "jsonrpc": "2.0", "result": "'
46-
SIZED_MSG_END = b'"}\n' b""
50+
SIZED_MSG_END = b'"}\n'
4751

4852

4953
@pytest.fixture
@@ -100,9 +104,9 @@ def server_fixture(response_fn):
100104
@pytest.fixture
101105
def serve_empty_result(ipc_server_fixture):
102106
def response_fn(connection):
103-
connection.sendall(b'{"id": 0, "result": {}')
107+
connection.sendall(b'{"id": 0, "result": {}}')
104108
time.sleep(0.1)
105-
connection.sendall(b"}\n")
109+
connection.sendall(b"\n")
106110

107111
yield from ipc_server_fixture(response_fn)
108112

@@ -342,3 +346,20 @@ async def test_async_ipc_read_buffer_limit_is_configurable(
342346
len(response["result"])
343347
== TWENTY_MB - len(SIZED_MSG_START) - len(SIZED_MSG_END) + 1024
344348
)
349+
350+
351+
@pytest.mark.asyncio
352+
async def test_async_ipc_provider_write_messages_end_with_new_line_delimiter(
353+
simple_ipc_server,
354+
jsonrpc_ipc_pipe_path,
355+
):
356+
async with AsyncWeb3(AsyncIPCProvider(pathlib.Path(jsonrpc_ipc_pipe_path))) as w3:
357+
w3.provider._writer.write = Mock()
358+
w3.provider._reader.readline = AsyncMock(
359+
return_value=b'{"id": 0, "result": {}}\n'
360+
)
361+
362+
await w3.provider.make_request("method", [])
363+
364+
request_data = b'{"jsonrpc": "2.0", "method": "method", "params": [], "id": 0}'
365+
w3.provider._writer.write.assert_called_with(request_data + b"\n")

0 commit comments

Comments
 (0)