diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/const.py b/deltachat-rpc-client/src/deltachat_rpc_client/const.py index 2a27b0a9a..e1cfd7685 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/const.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/const.py @@ -61,6 +61,7 @@ class EventType(str, Enum): WEBXDC_INSTANCE_DELETED = "WebxdcInstanceDeleted" CHATLIST_CHANGED = "ChatlistChanged" CHATLIST_ITEM_CHANGED = "ChatlistItemChanged" + TEST_CHECKPOINT_EVENT = "TestCheckpointEvent" class ChatId(IntEnum): diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py b/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py index fc8dba557..d077b8e0b 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py @@ -6,10 +6,12 @@ import logging import os import subprocess import sys -from queue import Empty, Queue +from queue import Queue from threading import Event, Thread from typing import Any, Iterator, Optional +from .const import EventType + class JsonRpcError(Exception): pass @@ -190,12 +192,11 @@ class Rpc: def clear_all_events(self, account_id: int): """Removes all queued-up events for a given account. Useful for tests.""" - queue = self.get_queue(account_id) - try: - while True: - queue.get_nowait() - except Empty: - pass + id = self.trigger_checkpoint_event(account_id) + while True: + event = self.wait_for_event(account_id) + if event.kind == EventType.TEST_CHECKPOINT_EVENT and event.id == id: + break def __getattr__(self, attr: str): return RpcMethod(self, attr)