20 lines
678 B
Python
20 lines
678 B
Python
|
|
import asyncio
|
||
|
|
import json
|
||
|
|
|
||
|
|
from tamq.service import request
|
||
|
|
|
||
|
|
|
||
|
|
def test_request_round_trip(tmp_path):
|
||
|
|
async def run():
|
||
|
|
path = tmp_path / "tamq.sock"
|
||
|
|
async def handle(reader, writer):
|
||
|
|
payload = json.loads(await reader.readline())
|
||
|
|
writer.write((json.dumps({"ok": payload["op"] == "ping"}) + "\n").encode())
|
||
|
|
await writer.drain(); writer.close(); await writer.wait_closed()
|
||
|
|
server = await asyncio.start_unix_server(handle, path=str(path))
|
||
|
|
try:
|
||
|
|
assert await request({"op": "ping"}, path) == {"ok": True}
|
||
|
|
finally:
|
||
|
|
server.close(); await server.wait_closed()
|
||
|
|
asyncio.run(run())
|