Skip to content

Commit

Permalink
python: remove arbitrary timeouts from tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
link2xt committed Feb 6, 2022
1 parent 276daf6 commit c4b0f77
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
4 changes: 1 addition & 3 deletions python/src/deltachat/direct_imap.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ def idle_check(self, terminate=False):
""" (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))
Expand Down
5 changes: 2 additions & 3 deletions python/src/deltachat/testplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ def finalize(self):
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:
Expand Down Expand Up @@ -483,7 +482,7 @@ def _run_stdout_thread(self) -> None:
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):
Expand All @@ -492,7 +491,7 @@ def fnmatch_lines(self, pattern_lines):
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")
Expand Down
28 changes: 15 additions & 13 deletions python/tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,6 @@ def test_configure_generate_key(self, acfactory, lp):
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)

Expand Down Expand Up @@ -1834,7 +1832,6 @@ def test_ac_setup_message(self, acfactory, lp):
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()
Expand All @@ -1851,7 +1848,6 @@ def test_ac_setup_message(self, acfactory, lp):
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")
Expand Down Expand Up @@ -2025,7 +2021,7 @@ def ac_member_removed(self, chat, contact, message):

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()) == \
Expand All @@ -2035,29 +2031,29 @@ def ac_member_removed(self, chat, contact, message):
# 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

Expand Down Expand Up @@ -2682,7 +2678,13 @@ def test_scan_folders(self, acfactory, lp, folder, move, expected_destination):
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 + ")")
Expand Down

0 comments on commit c4b0f77

Please sign in to comment.