-
-
Notifications
You must be signed in to change notification settings - Fork 143
feat: perform background fetch from all transports #8592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hpk42
wants to merge
2
commits into
main
Choose a base branch
from
hpk/background-fetch-all-transports
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,3 +1,4 @@ | ||||||
| import time | ||||||
| import urllib.parse | ||||||
|
|
||||||
| import pytest | ||||||
|
|
@@ -7,6 +8,24 @@ | |||||
| from deltachat_rpc_client.rpc import JsonRpcError | ||||||
|
|
||||||
|
|
||||||
| def alice_with_two_transports_and_bob(acf): | ||||||
| alice, bob = acf.get_online_accounts(2) | ||||||
| alice.add_transport_from_qr(acf.get_account_qr()) | ||||||
| alice.bring_online() | ||||||
| return alice, alice.create_chat(bob), bob.create_chat(alice) | ||||||
|
|
||||||
|
|
||||||
| def messages_with_text(chat, text): | ||||||
| return [msg for msg in chat.get_messages() if msg.get_snapshot().text == text] | ||||||
|
|
||||||
|
|
||||||
| def wait_for_imap_message(imap, timeout=60): | ||||||
| deadline = time.time() + timeout | ||||||
| while not imap.get_all_messages(): | ||||||
| assert time.time() < deadline, f"no message arrived in {imap.addr}" | ||||||
| time.sleep(1) | ||||||
|
|
||||||
|
|
||||||
| def test_add_second_address(acf) -> None: | ||||||
| account = acf.new_configured_account() | ||||||
| assert len(account.list_transports()) == 1 | ||||||
|
|
@@ -251,11 +270,10 @@ def test_message_info_imap_urls(acf) -> None: | |||||
| alice, bob = acf.get_online_accounts(2) | ||||||
|
|
||||||
| qr = acf.get_account_qr() | ||||||
| for i in range(3): | ||||||
| for _ in range(3): | ||||||
| alice.add_transport_from_qr(qr) | ||||||
| # Wait for all transports to go IDLE after adding each one. | ||||||
| for _ in range(i + 1): | ||||||
| alice.bring_online() | ||||||
| alice.bring_online() | ||||||
|
|
||||||
| # Enable multi-device mode so messages are not deleted immediately. | ||||||
| alice.set_config("bcc_self", "1") | ||||||
|
|
@@ -287,14 +305,7 @@ def test_message_info_imap_urls(acf) -> None: | |||||
|
|
||||||
| def test_remove_primary_transport(acf, log) -> None: | ||||||
| """Test that after removing the primary relay, Alice can still receive messages.""" | ||||||
| alice, bob = acf.get_online_accounts(2) | ||||||
| qr = acf.get_account_qr() | ||||||
|
|
||||||
| alice.add_transport_from_qr(qr) | ||||||
| alice.bring_online() | ||||||
|
|
||||||
| bob_chat = bob.create_chat(alice) | ||||||
| alice.create_chat(bob) | ||||||
| alice, alice_chat, bob_chat = alice_with_two_transports_and_bob(acf) | ||||||
|
|
||||||
| log.section("Alice sets up second transport") | ||||||
| [transport1, transport2] = alice.list_transports() | ||||||
|
|
@@ -313,7 +324,7 @@ def test_remove_primary_transport(acf, log) -> None: | |||||
| msg2 = alice.wait_for_incoming_msg().get_snapshot() | ||||||
| assert msg2.text == "Hello again!" | ||||||
| assert msg2.chat.get_basic_snapshot().chat_type == ChatType.SINGLE | ||||||
| assert msg2.chat == alice.create_chat(bob) | ||||||
| assert msg2.chat == alice_chat | ||||||
|
|
||||||
|
|
||||||
| def test_qr_works_after_removing_primary_transport(acf, log) -> None: | ||||||
|
|
@@ -344,3 +355,33 @@ def test_qr_works_after_removing_primary_transport(acf, log) -> None: | |||||
| bob.secure_join(chat_qr) | ||||||
| alice.wait_for_securejoin_inviter_success() | ||||||
| bob.wait_for_securejoin_joiner_success() | ||||||
|
|
||||||
|
|
||||||
| def test_background_fetch_from_second_transport(acf, direct_imap, dc): | ||||||
| alice, alice_chat, bob_chat = alice_with_two_transports_and_bob(acf) | ||||||
| [transport1, transport2] = alice.list_transports() | ||||||
| assert alice.get_config("configured_addr") == transport1["addr"] | ||||||
|
|
||||||
| alice.stop_io() | ||||||
| bob_chat.send_text("hello") | ||||||
| imap1 = direct_imap(alice, transport1["addr"], transport1["password"]) | ||||||
| wait_for_imap_message(direct_imap(alice, transport2["addr"], transport2["password"])) | ||||||
| wait_for_imap_message(imap1) | ||||||
|
|
||||||
| # Leave the message on the second transport only. | ||||||
| imap1.delete("1:*") | ||||||
|
|
||||||
| dc.background_fetch(30) | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about the timeout
Suggested change
|
||||||
| assert len(messages_with_text(alice_chat, "hello")) == 1 | ||||||
|
|
||||||
|
|
||||||
| def test_background_fetch_no_duplicates(acf, direct_imap, dc): | ||||||
| alice, alice_chat, bob_chat = alice_with_two_transports_and_bob(acf) | ||||||
|
|
||||||
| alice.stop_io() | ||||||
| bob_chat.send_text("hello") | ||||||
| for transport in alice.list_transports(): | ||||||
| wait_for_imap_message(direct_imap(alice, transport["addr"], transport["password"])) | ||||||
|
|
||||||
| dc.background_fetch(30) | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here
Suggested change
|
||||||
| assert len(messages_with_text(alice_chat, "hello")) == 1 | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some runners are randomly paused in CI (according to link2xt, who knows our CI better than I do), which means that a 60s timeout can be too short and lead to unnecessary flakiness. Instead, it's better not to have a timeout here. The global pytest timeout is enough, and it is is easily configurable across all tests rather than being different per test.