From 5e39a13bf684f21b1f9103f145e529e66d3c47aa Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sat, 30 Apr 2022 16:13:49 +0200 Subject: [PATCH] refine waiting for initial startup waiting for "INBOX: Idle" ready this slows down initialization for tests but provides more stability in my runs --- python/src/deltachat/events.py | 4 ++-- python/src/deltachat/testplugin.py | 33 ++++++++++++++---------------- python/tests/test_account.py | 11 ++++------ 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/python/src/deltachat/events.py b/python/src/deltachat/events.py index 4030cd029..35becadf1 100644 --- a/python/src/deltachat/events.py +++ b/python/src/deltachat/events.py @@ -156,14 +156,14 @@ class FFIEventTracker: print("** SECUREJOINT-INVITER PROGRESS {}".format(target), self.account) break - def wait_all_initial_fetches(self): + def wait_idle_inbox_ready(self): """Has to be called after start_io() to wait for fetch_existing_msgs to run so that new messages are not mistaken for old ones: - ac1 and ac2 are created - ac1 sends a message to ac2 - ac2 is still running FetchExsistingMsgs job and thinks it's an existing, old message - therefore no DC_EVENT_INCOMING_MSG is sent""" - self.get_info_contains("Done fetching existing messages") + self.get_info_contains("INBOX: Idle entering") def wait_next_incoming_message(self): """ wait for and return next incoming message. """ diff --git a/python/src/deltachat/testplugin.py b/python/src/deltachat/testplugin.py index 46a10c9c7..3423caffe 100644 --- a/python/src/deltachat/testplugin.py +++ b/python/src/deltachat/testplugin.py @@ -332,19 +332,21 @@ class ACFactory: def get_one_online_account(self, move=False): ac1 = self.get_online_configuring_account(move=move) - self.wait_configure_and_start_io([ac1]) + self.wait_configure_and_start_io() return ac1 def get_two_online_accounts(self, move=False, quiet=False): ac1 = self.get_online_configuring_account(move=move, quiet=quiet) ac2 = self.get_online_configuring_account(quiet=quiet) - self.wait_configure_and_start_io([ac1, ac2]) + self.wait_configure_and_start_io() return ac1, ac2 def get_many_online_accounts(self, num, move=True): accounts = [self.get_online_configuring_account(move=move, quiet=True) for i in range(num)] - self.wait_configure_and_start_io(accounts) + self.wait_configure_and_start_io() + # to reduce logging for higher level tests, logging only starts + # after initial successful configuration for acc in accounts: acc.add_account_plugin(FFIEventLogger(acc)) return accounts @@ -370,21 +372,16 @@ class ACFactory: ac._configtracker = ac.configure() return ac - def wait_configure_and_start_io(self, accounts=None): - if accounts is None: - accounts = self._accounts[:] - started_accounts = [] - for acc in accounts: - if acc not in started_accounts: - self.wait_configure(acc) - acc.set_config("bcc_self", "0") - if acc.is_configured(): - acc.start_io() - started_accounts.append(acc) - print("{}: {} account was started".format( - acc.get_config("displayname"), acc.get_config("addr"))) - for acc in started_accounts: - acc._evtracker.wait_all_initial_fetches() + def wait_configure_and_start_io(self): + for acc in self._accounts: + self.wait_configure(acc) + acc.set_config("bcc_self", "0") + acc.start_io() + print("{}: {} waiting for inbox idle to become ready".format( + acc.get_config("displayname"), acc.get_config("addr"))) + acc._evtracker.wait_idle_inbox_ready() + print("{}: {} account IMAP IO ready to receive".format( + acc.get_config("displayname"), acc.get_config("addr"))) def wait_configure(self, acc): if hasattr(acc, "_configtracker"): diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 4463d9dcc..fcaf0a890 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -1049,7 +1049,7 @@ class TestOnlineAccount: """Test that message already moved to DeltaChat folder is marked as seen.""" ac1 = acfactory.get_online_configuring_account() ac2 = acfactory.get_online_configuring_account(move=True) - acfactory.wait_configure_and_start_io([ac1, ac2]) + acfactory.wait_configure_and_start_io() ac2.stop_io() ac2.direct_imap.idle_start() @@ -1447,8 +1447,6 @@ class TestOnlineAccount: ac1.direct_imap.create_folder("Junk") acfactory.wait_configure_and_start_io() - # Wait until each folder was selected once and we are IDLEing again: - ac1._evtracker.get_info_contains("INBOX: Idle entering wait-on-remote state") ac1.stop_io() ac1.direct_imap.append("Drafts", """ @@ -1495,7 +1493,7 @@ class TestOnlineAccount: msg = ac1._evtracker.wait_next_messages_changed() # Wait until each folder was scanned, this is necessary for this test to test what it should test: - ac1._evtracker.get_info_contains("INBOX: Idle entering wait-on-remote state") + ac1._evtracker.wait_idle_inbox_ready() assert msg.text == "subj – message in Sent" assert len(msg.chat.get_messages()) == 1 @@ -2394,7 +2392,7 @@ class TestOnlineAccount: chat41 = ac4.create_chat(ac1) chat42 = ac4.create_chat(ac2) ac4.start_io() - ac4._evtracker.wait_all_initial_fetches() + ac4._evtracker.wait_idle_inbox_ready() lp.sec("ac1: creating group chat with 2 other members") chat = ac1.create_group_chat("title", contacts=[ac2, ac3]) @@ -2723,7 +2721,6 @@ class TestOnlineAccount: acfactory.wait_configure_and_start_io() # Wait until each folder was selected once and we are IDLEing: - ac1._evtracker.get_info_contains("INBOX: Idle entering wait-on-remote state") ac1.stop_io() # Send a message to ac1 and move it to the mvbox: @@ -2843,7 +2840,7 @@ class TestOnlineAccount: ac1_clone._configtracker.wait_finish() ac1_clone.start_io() - ac1_clone._evtracker.wait_all_initial_fetches() + ac1_clone._evtracker.wait_idle_inbox_ready() chats = ac1_clone.get_chats() assert len(chats) == 4 # two newly created chats + self-chat + device-chat group_chat = [c for c in chats if c.get_name() == "group name"][0]