slightly refine increation tests wrt to ordering

This commit is contained in:
holger krekel
2020-05-22 12:46:12 +02:00
parent 7c8758dc26
commit f97538a399

View File

@@ -10,29 +10,27 @@ from deltachat import const
def wait_msg_delivered(account, msg_list):
""" wait for one or more MSG_DELIVERED events to match msg_list contents. """
msg_list = list(msg_list)
while msg_list:
ev = account._evtracker.get_matching("DC_EVENT_MSG_DELIVERED")
msg_list.remove((ev.data1, ev.data2))
def get_msgs_changed(account):
while 1:
def wait_msgs_changed(account, msgs_list):
""" wait for one or more MSGS_CHANGED events to match msgs_list contents. """
account.log("waiting for msgs_list={}".format(msgs_list))
msgs_list = list(msgs_list)
while msgs_list:
ev = account._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
yield (ev.data1, ev.data2)
def wait_msgs_changed(account, chat_id, msg_id=None):
account.log("waiting for chat_id={} msg_id={}".format(chat_id, msg_id))
while 1:
ev = account._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
if ev.data1 != chat_id:
account.log("waiting got mismatched DC_EVENT_MSGS_CHANGED")
account.log("expect chat_id={} got data1={}".format(chat_id, ev.data1))
continue
if msg_id is not None:
assert ev.data2 == msg_id
account.log("WAIT -> FOUND chat_id={} msg_id={}".format(chat_id, msg_id))
return ev.data2
for i, (data1, data2) in enumerate(msgs_list):
if ev.data1 == data1:
if data2 is None or ev.data2 == data2:
del msgs_list[i]
break
else:
account.log("waiting mismatch data1={} data2={}".format(data1, data2))
return ev.data1, ev.data2
class TestOnlineInCreation:
@@ -69,7 +67,7 @@ class TestOnlineInCreation:
c2 = ac1.create_contact(email=ac2.get_config("addr"))
chat = ac1.create_chat_by_contact(c2)
assert chat.id >= const.DC_CHAT_ID_LAST_SPECIAL
wait_msgs_changed(ac1, 0, 0) # why no chat id?
wait_msgs_changed(ac1, [(0, 0)]) # why no chat id?
lp.sec("create a message with a file in creation")
orig = data.get_path("d.png")
@@ -78,19 +76,16 @@ class TestOnlineInCreation:
fp.write("preparing")
prepared_original = chat.prepare_message_file(path)
assert prepared_original.is_out_preparing()
wait_msgs_changed(ac1, chat.id, prepared_original.id)
wait_msgs_changed(ac1, [(chat.id, prepared_original.id)])
lp.sec("forward the message while still in creation")
chat2 = ac1.create_group_chat("newgroup")
chat2.add_contact(c2)
wait_msgs_changed(ac1, 0, 0) # why not chat id?
wait_msgs_changed(ac1, [(0, 0)]) # why not chat id?
ac1.forward_messages([prepared_original], chat2)
# XXX there might be two EVENT_MSGS_CHANGED and only one of them
# is the one caused by forwarding
forwarded_id = wait_msgs_changed(ac1, chat2.id)
if forwarded_id == 0:
forwarded_id = wait_msgs_changed(ac1, chat2.id)
assert forwarded_id
_, forwarded_id = wait_msgs_changed(ac1, [(chat2.id, None)])
forwarded_msg = ac1.get_message_by_id(forwarded_id)
assert forwarded_msg.is_out_preparing()
@@ -101,16 +96,10 @@ class TestOnlineInCreation:
assert prepared_original.is_out_pending() or prepared_original.is_out_delivered()
lp.sec("check that both forwarded and original message are proper.")
forwarded, original = False, False
for chat_id, msg_id in get_msgs_changed(ac1):
if chat_id == chat2.id and msg_id == forwarded_id:
forwarded = True
fwd_msg = ac1.get_message_by_id(forwarded_id)
assert fwd_msg.is_out_pending() or fwd_msg.is_out_delivered()
elif chat_id == chat.id and msg_id == prepared_original.id:
original = True
if forwarded and original:
break
wait_msgs_changed(ac1, [(chat2.id, forwarded_id), (chat.id, prepared_original.id)])
fwd_msg = ac1.get_message_by_id(forwarded_id)
assert fwd_msg.is_out_pending() or fwd_msg.is_out_delivered()
lp.sec("wait for both messages to be delivered to SMTP")
wait_msg_delivered(ac1, [