From 45b5f6ddeddfb42958a2876e1c251086a0828698 Mon Sep 17 00:00:00 2001 From: link2xt Date: Fri, 14 Nov 2025 23:27:52 +0000 Subject: [PATCH 1/3] api(deltachat-rpc-client): add APIs for background fetch --- .../src/deltachat_rpc_client/deltachat.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/deltachat.py b/deltachat-rpc-client/src/deltachat_rpc_client/deltachat.py index 58ee30b322..3d23eac46f 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/deltachat.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/deltachat.py @@ -4,7 +4,7 @@ from typing import TYPE_CHECKING -from ._utils import AttrDict +from ._utils import AttrDict, futuremethod from .account import Account if TYPE_CHECKING: @@ -39,6 +39,15 @@ def stop_io(self) -> None: """Stop the I/O of all accounts.""" self.rpc.stop_io_for_all_accounts() + @futuremethod + def background_fetch(self, timeout_in_seconds: int) -> None: + """Run background fetch for all accounts.""" + yield self.rpc.background_fetch.future(timeout_in_seconds) + + def stop_background_fetch(self) -> None: + """Stop ongoing background fetch.""" + self.rpc.stop_background_fetch() + def maybe_network(self) -> None: """Indicate that the network conditions might have changed.""" self.rpc.maybe_network() From 295f8c86acd0f7d38cf4007b24d3ee3dd82ce0a4 Mon Sep 17 00:00:00 2001 From: link2xt Date: Fri, 14 Nov 2025 23:27:52 +0000 Subject: [PATCH 2/3] test: add pytest fixture for account manager --- .../src/deltachat_rpc_client/pytestplugin.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py b/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py index ff3a929856..1516b8f718 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py @@ -135,9 +135,15 @@ def rpc(tmp_path) -> AsyncGenerator: @pytest.fixture -def acfactory(rpc) -> AsyncGenerator: +def dc(rpc) -> DeltaChat: + """Return account manager.""" + return DeltaChat(rpc) + + +@pytest.fixture +def acfactory(dc) -> AsyncGenerator: """Return account factory fixture.""" - return ACFactory(DeltaChat(rpc)) + return ACFactory(dc) @pytest.fixture From 822191431a817ae740ba85cfc4aae0061fdb8e17 Mon Sep 17 00:00:00 2001 From: link2xt Date: Fri, 14 Nov 2025 23:27:52 +0000 Subject: [PATCH 3/3] test: test background_fetch() and stop_background_fetch() --- deltachat-rpc-client/tests/test_something.py | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/deltachat-rpc-client/tests/test_something.py b/deltachat-rpc-client/tests/test_something.py index 8e882896e2..7eeed4de7a 100644 --- a/deltachat-rpc-client/tests/test_something.py +++ b/deltachat-rpc-client/tests/test_something.py @@ -965,3 +965,40 @@ def test_immediate_autodelete(acfactory, direct_imap, log): ev = ac1.wait_for_event(EventType.MSG_READ) assert ev.chat_id == chat1.id assert ev.msg_id == sent_msg.id + + +def test_background_fetch(acfactory, dc): + ac1, ac2 = acfactory.get_online_accounts(2) + ac1.stop_io() + + ac1_chat = ac1.create_chat(ac2) + + ac2_chat = ac2.create_chat(ac1) + ac2_chat.send_text("Hello!") + + while True: + dc.background_fetch(300) + messages = ac1_chat.get_messages() + snapshot = messages[-1].get_snapshot() + if snapshot.text == "Hello!": + break + + # Stopping background fetch immediately after starting + # does not result in any errors. + background_fetch_future = dc.background_fetch.future(300) + dc.stop_background_fetch() + background_fetch_future() + + # Starting background fetch with zero timeout is ok, + # it should terminate immediately. + dc.background_fetch(0) + + # Background fetch can still be used to send and receive messages. + ac2_chat.send_text("Hello again!") + + while True: + dc.background_fetch(300) + messages = ac1_chat.get_messages() + snapshot = messages[-1].get_snapshot() + if snapshot.text == "Hello again!": + break