mirror of
https://github.com/chatmail/core.git
synced 2026-05-05 22:36:30 +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")}
|
env = {**os.environ, "DC_ACCOUNTS_PATH": str(tmp_path / "accounts")}
|
||||||
async with start_rpc_server(env=env) as rpc:
|
async with start_rpc_server(env=env) as rpc:
|
||||||
yield rpc
|
yield rpc
|
||||||
await asyncio.sleep(0.1) # avoid RuntimeError: Event loop is closed
|
|
||||||
|
|
||||||
|
|
||||||
@pytest_asyncio.fixture
|
@pytest_asyncio.fixture
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ class Rpc:
|
|||||||
else:
|
else:
|
||||||
print(response)
|
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]:
|
async def wait_for_event(self, account_id: int) -> Optional[dict]:
|
||||||
"""Waits for the next event from the given account and returns it."""
|
"""Waits for the next event from the given account and returns it."""
|
||||||
if account_id in self.event_queues:
|
if account_id in self.event_queues:
|
||||||
@@ -84,4 +89,4 @@ async def start_rpc_server(*args, **kwargs) -> AsyncGenerator:
|
|||||||
try:
|
try:
|
||||||
yield rpc
|
yield rpc
|
||||||
finally:
|
finally:
|
||||||
proc.terminate()
|
await rpc.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user