diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py b/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py index b8929ed29..bda51cdd5 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py @@ -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 diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py b/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py index b0cc36528..bd42044a5 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py @@ -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()