refine waiting for initial startup waiting for "INBOX: Idle" ready

this slows down initialization for tests but provides more stability in my runs
This commit is contained in:
holger krekel
2022-04-30 16:13:49 +02:00
parent 720c1b5eca
commit 5e39a13bf6
3 changed files with 21 additions and 27 deletions

View File

@@ -156,14 +156,14 @@ class FFIEventTracker:
print("** SECUREJOINT-INVITER PROGRESS {}".format(target), self.account) print("** SECUREJOINT-INVITER PROGRESS {}".format(target), self.account)
break 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 """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: so that new messages are not mistaken for old ones:
- ac1 and ac2 are created - ac1 and ac2 are created
- ac1 sends a message to ac2 - ac1 sends a message to ac2
- ac2 is still running FetchExsistingMsgs job and thinks it's an existing, old message - ac2 is still running FetchExsistingMsgs job and thinks it's an existing, old message
- therefore no DC_EVENT_INCOMING_MSG is sent""" - 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): def wait_next_incoming_message(self):
""" wait for and return next incoming message. """ """ wait for and return next incoming message. """

View File

@@ -332,19 +332,21 @@ class ACFactory:
def get_one_online_account(self, move=False): def get_one_online_account(self, move=False):
ac1 = self.get_online_configuring_account(move=move) ac1 = self.get_online_configuring_account(move=move)
self.wait_configure_and_start_io([ac1]) self.wait_configure_and_start_io()
return ac1 return ac1
def get_two_online_accounts(self, move=False, quiet=False): def get_two_online_accounts(self, move=False, quiet=False):
ac1 = self.get_online_configuring_account(move=move, quiet=quiet) ac1 = self.get_online_configuring_account(move=move, quiet=quiet)
ac2 = self.get_online_configuring_account(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 return ac1, ac2
def get_many_online_accounts(self, num, move=True): def get_many_online_accounts(self, num, move=True):
accounts = [self.get_online_configuring_account(move=move, quiet=True) accounts = [self.get_online_configuring_account(move=move, quiet=True)
for i in range(num)] 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: for acc in accounts:
acc.add_account_plugin(FFIEventLogger(acc)) acc.add_account_plugin(FFIEventLogger(acc))
return accounts return accounts
@@ -370,21 +372,16 @@ class ACFactory:
ac._configtracker = ac.configure() ac._configtracker = ac.configure()
return ac return ac
def wait_configure_and_start_io(self, accounts=None): def wait_configure_and_start_io(self):
if accounts is None: for acc in self._accounts:
accounts = self._accounts[:] self.wait_configure(acc)
started_accounts = [] acc.set_config("bcc_self", "0")
for acc in accounts: acc.start_io()
if acc not in started_accounts: print("{}: {} waiting for inbox idle to become ready".format(
self.wait_configure(acc) acc.get_config("displayname"), acc.get_config("addr")))
acc.set_config("bcc_self", "0") acc._evtracker.wait_idle_inbox_ready()
if acc.is_configured(): print("{}: {} account IMAP IO ready to receive".format(
acc.start_io() acc.get_config("displayname"), acc.get_config("addr")))
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(self, acc): def wait_configure(self, acc):
if hasattr(acc, "_configtracker"): if hasattr(acc, "_configtracker"):

View File

@@ -1049,7 +1049,7 @@ class TestOnlineAccount:
"""Test that message already moved to DeltaChat folder is marked as seen.""" """Test that message already moved to DeltaChat folder is marked as seen."""
ac1 = acfactory.get_online_configuring_account() ac1 = acfactory.get_online_configuring_account()
ac2 = acfactory.get_online_configuring_account(move=True) 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.stop_io()
ac2.direct_imap.idle_start() ac2.direct_imap.idle_start()
@@ -1447,8 +1447,6 @@ class TestOnlineAccount:
ac1.direct_imap.create_folder("Junk") ac1.direct_imap.create_folder("Junk")
acfactory.wait_configure_and_start_io() 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.stop_io()
ac1.direct_imap.append("Drafts", """ ac1.direct_imap.append("Drafts", """
@@ -1495,7 +1493,7 @@ class TestOnlineAccount:
msg = ac1._evtracker.wait_next_messages_changed() 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: # 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 msg.text == "subj message in Sent"
assert len(msg.chat.get_messages()) == 1 assert len(msg.chat.get_messages()) == 1
@@ -2394,7 +2392,7 @@ class TestOnlineAccount:
chat41 = ac4.create_chat(ac1) chat41 = ac4.create_chat(ac1)
chat42 = ac4.create_chat(ac2) chat42 = ac4.create_chat(ac2)
ac4.start_io() 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") lp.sec("ac1: creating group chat with 2 other members")
chat = ac1.create_group_chat("title", contacts=[ac2, ac3]) chat = ac1.create_group_chat("title", contacts=[ac2, ac3])
@@ -2723,7 +2721,6 @@ class TestOnlineAccount:
acfactory.wait_configure_and_start_io() acfactory.wait_configure_and_start_io()
# Wait until each folder was selected once and we are IDLEing: # 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() ac1.stop_io()
# Send a message to ac1 and move it to the mvbox: # Send a message to ac1 and move it to the mvbox:
@@ -2843,7 +2840,7 @@ class TestOnlineAccount:
ac1_clone._configtracker.wait_finish() ac1_clone._configtracker.wait_finish()
ac1_clone.start_io() ac1_clone.start_io()
ac1_clone._evtracker.wait_all_initial_fetches() ac1_clone._evtracker.wait_idle_inbox_ready()
chats = ac1_clone.get_chats() chats = ac1_clone.get_chats()
assert len(chats) == 4 # two newly created chats + self-chat + device-chat 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] group_chat = [c for c in chats if c.get_name() == "group name"][0]