mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
Properly terminate Rpc and remove sleep() hack
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user