Properly terminate Rpc and remove sleep() hack

This commit is contained in:
link2xt
2022-12-03 23:30:50 +00:00
parent 98b6b5e3f6
commit 5a3065344e
2 changed files with 6 additions and 2 deletions

View File

@@ -44,7 +44,6 @@ async def rpc(tmp_path) -> AsyncGenerator:
env = {**os.environ, "DC_ACCOUNTS_PATH": str(tmp_path / "accounts")}
async with start_rpc_server(env=env) as rpc:
yield rpc
await asyncio.sleep(0.1) # avoid RuntimeError: Event loop is closed
@pytest_asyncio.fixture

View File

@@ -37,6 +37,11 @@ class Rpc:
else:
print(response)
async def close(self) -> None:
"""Terminate RPC server process and wait until the reader loop finishes."""
self.process.terminate()
await self.reader_task
async def wait_for_event(self, account_id: int) -> Optional[dict]:
"""Waits for the next event from the given account and returns it."""
if account_id in self.event_queues:
@@ -84,4 +89,4 @@ async def start_rpc_server(*args, **kwargs) -> AsyncGenerator:
try:
yield rpc
finally:
proc.terminate()
await rpc.close()