From c4b0f773db6b34846757446891c25064d41b7f7a Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 5 Feb 2022 15:04:59 +0000 Subject: [PATCH] python: remove arbitrary timeouts from tests pytest-timeout already handles all deadlocks and is configurable with --timeout option. With this change it is possible to disable timeout with --timeout 0 to run tests on extremely slow connections. --- python/src/deltachat/direct_imap.py | 4 +--- python/src/deltachat/testplugin.py | 5 ++--- python/tests/test_account.py | 28 +++++++++++++++------------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/python/src/deltachat/direct_imap.py b/python/src/deltachat/direct_imap.py index 74b967401..71c46b7b8 100644 --- a/python/src/deltachat/direct_imap.py +++ b/python/src/deltachat/direct_imap.py @@ -224,9 +224,7 @@ class DirectImap: """ (blocking) wait for next idle message from server. """ assert self._idling self.account.log("imap-direct: calling idle_check") - res = self.conn.idle_check(timeout=30) - if len(res) == 0: - raise TimeoutError + res = self.conn.idle_check() if terminate: self.idle_done() self.account.log("imap-direct: idle_check returned {!r}".format(res)) diff --git a/python/src/deltachat/testplugin.py b/python/src/deltachat/testplugin.py index a1095befd..8e63663b7 100644 --- a/python/src/deltachat/testplugin.py +++ b/python/src/deltachat/testplugin.py @@ -241,7 +241,6 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data): def make_account(self, path, logid, quiet=False): ac = Account(path, logging=self._logging) ac._evtracker = ac.add_account_plugin(FFIEventTracker(ac)) - ac._evtracker.set_timeout(30) ac.addr = ac.get_self_contact().addr ac.set_config("displayname", logid) if not quiet: @@ -483,7 +482,7 @@ class BotProcess: def kill(self) -> None: self.popen.kill() - def wait(self, timeout=30) -> None: + def wait(self, timeout=None) -> None: self.popen.wait(timeout=timeout) def fnmatch_lines(self, pattern_lines): @@ -492,7 +491,7 @@ class BotProcess: print("+++FNMATCH:", next_pattern) ignored = [] while 1: - line = self.stdout_queue.get(timeout=15) + line = self.stdout_queue.get() if line is None: if ignored: print("BOT stdout terminated after these lines") diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 3e145021d..551457167 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -652,8 +652,6 @@ class TestOnlineAccount: pre_generated_key=False, config={"key_gen_type": str(const.DC_KEY_GEN_ED25519)} ) - # rsa key gen can be slow especially on CI, adjust timeout - ac1._evtracker.set_timeout(240) acfactory.wait_configure_and_start_io() chat = acfactory.get_accepted_chat(ac1, ac2) @@ -1834,7 +1832,6 @@ class TestOnlineAccount: lp.sec("trigger ac setup message and return setupcode") assert ac1.get_info()["fingerprint"] != ac2.get_info()["fingerprint"] setup_code = ac1.initiate_key_transfer() - ac2._evtracker.set_timeout(30) ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED") msg = ac2.get_message_by_id(ev.data2) assert msg.is_setup_message() @@ -1851,7 +1848,6 @@ class TestOnlineAccount: def test_ac_setup_message_twice(self, acfactory, lp): ac1 = acfactory.get_online_configuring_account() ac2 = acfactory.clone_online_account(ac1) - ac2._evtracker.set_timeout(30) acfactory.wait_configure_and_start_io() lp.sec("trigger ac setup message but ignore") @@ -2025,7 +2021,7 @@ class TestOnlineAccount: lp.sec("ac1: send a message to group chat to promote the group") chat.send_text("afterwards promoted") - ev = in_list.get(timeout=10) + ev = in_list.get() assert ev.action == "chat-modified" assert chat.is_promoted() assert sorted(x.addr for x in chat.get_contacts()) == \ @@ -2035,29 +2031,29 @@ class TestOnlineAccount: # note that if the above create_chat() would not # happen we would not receive a proper member_added event contact2 = chat.add_contact("devnull@testrun.org") - ev = in_list.get(timeout=10) + ev = in_list.get() assert ev.action == "chat-modified" - ev = in_list.get(timeout=10) + ev = in_list.get() assert ev.action == "chat-modified" - ev = in_list.get(timeout=10) + ev = in_list.get() assert ev.action == "added" assert ev.message.get_sender_contact().addr == ac1_addr assert ev.contact.addr == "devnull@testrun.org" lp.sec("ac1: remove address2") chat.remove_contact(contact2) - ev = in_list.get(timeout=10) + ev = in_list.get() assert ev.action == "chat-modified" - ev = in_list.get(timeout=10) + ev = in_list.get() assert ev.action == "removed" assert ev.contact.addr == contact2.addr assert ev.message.get_sender_contact().addr == ac1_addr lp.sec("ac1: remove ac2 contact from chat") chat.remove_contact(ac2) - ev = in_list.get(timeout=10) + ev = in_list.get() assert ev.action == "chat-modified" - ev = in_list.get(timeout=10) + ev = in_list.get() assert ev.action == "removed" assert ev.message.get_sender_contact().addr == ac1_addr @@ -2682,7 +2678,13 @@ class TestOnlineAccount: ac1.direct_imap.select_config_folder("inbox") ac1.direct_imap.idle_start() acfactory.get_accepted_chat(ac2, ac1).send_text("hello") - ac1.direct_imap.idle_check(terminate=True) + while True: + if len(ac1.direct_imap.idle_check(terminate=True)) > 1: + # If length is 1, it's [(b'OK', b'Still here')] + # Could happen on very slow network. + # + # More is usually [(1, b'EXISTS'), (1, b'RECENT')] + break ac1.direct_imap.conn.move(["*"], folder) # "*" means "biggest UID in mailbox" lp.sec("Everything prepared, now see if DeltaChat finds the message (" + variant + ")")