diff --git a/python/src/deltachat/testplugin.py b/python/src/deltachat/testplugin.py index 910db5c71..ddc8ee9fc 100644 --- a/python/src/deltachat/testplugin.py +++ b/python/src/deltachat/testplugin.py @@ -310,13 +310,16 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data): ac1 = self.get_online_configuring_account( pre_generated_key=pre_generated_key, mvbox=mvbox, move=move) ac1.wait_configure_finish() + ac1.start() return ac1 def get_two_online_accounts(self, move=False, quiet=False): ac1 = self.get_online_configuring_account(move=True, quiet=quiet) ac2 = self.get_online_configuring_account(quiet=quiet) ac1.wait_configure_finish() + ac1.start() ac2.wait_configure_finish() + ac2.start() return ac1, ac2 def clone_online_account(self, account, pre_generated_key=True): diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 0cd14a9cc..e68c204a4 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -533,7 +533,9 @@ class TestOnlineAccount: # rsa key gen can be slow especially on CI, adjust timeout ac1._evtracker.set_timeout(120) ac1.wait_configure_finish() + ac1.start() ac2.wait_configure_finish() + ac2.start() chat = self.get_chat(ac1, ac2, both_created=True) lp.sec("ac1: send unencrypted message to ac2") @@ -560,7 +562,10 @@ class TestOnlineAccount: assert msg3_in.text == "message3" assert msg3_in.is_encrypted() - def test_configure_canceled(self, acfactory): + ac1.shutdown() + ac2.shutdown() + + def xtest_configure_canceled(self, acfactory): ac1 = acfactory.get_online_configuring_account() ac1._configtracker.wait_progress() ac1.stop_ongoing() @@ -569,6 +574,8 @@ class TestOnlineAccount: except ac1._configtracker.ConfigureFailed: pass + ac1.shutdown() + def test_export_import_self_keys(self, acfactory, tmpdir): ac1, ac2 = acfactory.get_two_online_accounts() @@ -580,6 +587,9 @@ class TestOnlineAccount: ac1._evtracker.consume_events() ac2.import_self_keys(dir.strpath) + ac1.shutdown() + ac2.shutdown() + def test_one_account_send_bcc_setting(self, acfactory, lp): ac1 = acfactory.get_online_configuring_account() ac2 = acfactory.get_online_configuring_account() @@ -589,8 +599,11 @@ class TestOnlineAccount: ac1_clone = acfactory.clone_online_account(ac1) ac1.wait_configure_finish() + ac1.start() ac2.wait_configure_finish() + ac2.start() ac1_clone.wait_configure_finish() + ac1_clone.start() chat = self.get_chat(ac1, ac2) @@ -630,6 +643,10 @@ class TestOnlineAccount: ev_msg = ac1_clone._evtracker.wait_next_messages_changed() assert ev_msg.text == msg_out.text + ac1.shutdown() + ac2.shutdown() + ac1_clone.shutdown() + def test_send_file_twice_unicode_filename_mangling(self, tmpdir, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() chat = self.get_chat(ac1, ac2) @@ -662,6 +679,9 @@ class TestOnlineAccount: assert msg2.filename.endswith("html.zip") assert msg.filename != msg2.filename + ac1.shutdown() + ac2.shutdown() + def test_send_file_html_attachment(self, tmpdir, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() chat = self.get_chat(ac1, ac2) @@ -686,6 +706,9 @@ class TestOnlineAccount: assert open(msg.filename).read() == content assert msg.filename.endswith(basename) + ac1.shutdown() + ac2.shutdown() + def test_mvbox_sentbox_threads(self, acfactory, lp): lp.sec("ac1: start with mvbox thread") ac1 = acfactory.get_online_configuring_account(mvbox=True, move=True, sentbox=True) @@ -695,9 +718,11 @@ class TestOnlineAccount: lp.sec("ac2: waiting for configuration") ac2.wait_configure_finish() + ac2.start() lp.sec("ac1: waiting for configuration") ac1.wait_configure_finish() + ac1.start() lp.sec("ac1: send message and wait for ac2 to receive it") chat = self.get_chat(ac1, ac2) @@ -706,23 +731,34 @@ class TestOnlineAccount: assert ev.data2 > const.DC_CHAT_ID_LAST_SPECIAL lp.sec("test finished") + ac1.shutdown() + ac2.shutdown() + def test_move_works(self, acfactory): ac1 = acfactory.get_online_configuring_account() ac2 = acfactory.get_online_configuring_account(mvbox=True, move=True) ac2.wait_configure_finish() + ac2.start() ac1.wait_configure_finish() + ac1.start() chat = self.get_chat(ac1, ac2) chat.send_text("message1") ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED") assert ev.data2 > const.DC_CHAT_ID_LAST_SPECIAL ac2._evtracker.get_matching("DC_EVENT_IMAP_MESSAGE_MOVED") + ac1.shutdown() + ac2.shutdown() + def test_move_works_on_self_sent(self, acfactory): ac1 = acfactory.get_online_configuring_account(mvbox=True, move=True) ac1.set_config("bcc_self", "1") ac2 = acfactory.get_online_configuring_account() ac2.wait_configure_finish() + ac2.start() ac1.wait_configure_finish() + ac1.start() + chat = self.get_chat(ac1, ac2) chat.send_text("message1") chat.send_text("message2") @@ -731,6 +767,9 @@ class TestOnlineAccount: ac1._evtracker.get_matching("DC_EVENT_IMAP_MESSAGE_MOVED") ac1._evtracker.get_matching("DC_EVENT_IMAP_MESSAGE_MOVED") + ac1.shutdown() + ac2.shutdown() + def test_forward_messages(self, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() chat = self.get_chat(ac1, ac2) @@ -764,6 +803,9 @@ class TestOnlineAccount: ac2.delete_messages(messages) assert not chat3.get_messages() + ac1.shutdown() + ac2.shutdown() + def test_forward_own_message(self, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() chat = self.get_chat(ac1, ac2, both_created=True) @@ -788,6 +830,9 @@ class TestOnlineAccount: assert msg_in.text == "message2" assert msg_in.is_forwarded() + ac1.shutdown() + ac2.shutdown() + def test_send_self_message_and_empty_folder(self, acfactory, lp): ac1 = acfactory.get_one_online_account(mvbox=True, move=True) lp.sec("ac1: create self chat") @@ -800,6 +845,8 @@ class TestOnlineAccount: boxes = sorted([ev1.data2, ev2.data2]) assert boxes == ["DeltaChat", "INBOX"] + ac1.shutdown() + def test_send_and_receive_message_markseen(self, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() @@ -869,6 +916,10 @@ class TestOnlineAccount: except queue.Empty: pass # mark_seen_messages() has generated events before it returns + ac1.shutdown() + ac2.shutdown() + + def test_mdn_asymetric(self, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts(move=True) @@ -904,6 +955,9 @@ class TestOnlineAccount: # MDN is received even though MDNs are already disabled assert msg_out.is_out_mdn_received() + ac1.shutdown() + ac2.shutdown() + def test_send_and_receive_will_encrypt_decrypt(self, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() @@ -953,6 +1007,9 @@ class TestOnlineAccount: ev = ac1._evtracker.get_matching("DC_EVENT_SMTP_MESSAGE_SENT") assert not msg.is_encrypted() + ac1.shutdown() + ac2.shutdown() + def test_send_first_message_as_long_unicode_with_cr(self, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() ac2.set_config("save_mime_headers", "1") @@ -979,6 +1036,9 @@ class TestOnlineAccount: assert msg_in.text == text2 assert ac1.get_config("addr") in msg_in.chat.get_name() + ac1.shutdown() + ac2.shutdown() + def test_reply_encrypted(self, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() @@ -1032,6 +1092,9 @@ class TestOnlineAccount: assert msg_in.text == "message2 -- should be encrypted" assert msg_in.is_encrypted() + ac1.shutdown() + ac2.shutdown() + def test_saved_mime_on_received_message(self, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() @@ -1051,6 +1114,9 @@ class TestOnlineAccount: assert mime.get_all("From") assert mime.get_all("Received") + ac1.shutdown() + ac2.shutdown() + def test_send_and_receive_image(self, acfactory, lp, data): ac1, ac2 = acfactory.get_two_online_accounts() chat = self.get_chat(ac1, ac2) @@ -1099,6 +1165,9 @@ class TestOnlineAccount: m = message_queue.get() assert m == msg_in + ac1.shutdown() + ac2.shutdown() + def test_import_export_online_all(self, acfactory, tmpdir, lp): ac1 = acfactory.get_one_online_account() @@ -1142,6 +1211,10 @@ class TestOnlineAccount: assert path2 != path assert ac2.get_latest_backupfile(backupdir.strpath) == path2 + ac1.shutdown() + ac2.shutdown() + + def test_ac_setup_message(self, acfactory, lp): # note that the receiving account needs to be configured and running # before ther setup message is send. DC does not read old messages @@ -1149,7 +1222,9 @@ class TestOnlineAccount: ac1 = acfactory.get_online_configuring_account() ac2 = acfactory.clone_online_account(ac1) ac2.wait_configure_finish() + ac2.start() ac1.wait_configure_finish() + ac1.start() lp.sec("trigger ac setup message and return setupcode") assert ac1.get_info()["fingerprint"] != ac2.get_info()["fingerprint"] @@ -1168,12 +1243,18 @@ class TestOnlineAccount: msg.continue_key_transfer(setup_code) assert ac1.get_info()["fingerprint"] == ac2.get_info()["fingerprint"] + ac1.shutdown() + ac2.shutdown() + + 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) ac2.wait_configure_finish() + ac2.start() ac1.wait_configure_finish() + ac1.start() lp.sec("trigger ac setup message but ignore") assert ac1.get_info()["fingerprint"] != ac2.get_info()["fingerprint"] @@ -1191,6 +1272,9 @@ class TestOnlineAccount: msg.continue_key_transfer(setup_code2) assert ac1.get_info()["fingerprint"] == ac2.get_info()["fingerprint"] + ac1.shutdown() + ac2.shutdown() + def test_qr_setup_contact(self, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() lp.sec("ac1: create QR code and let ac2 scan it, starting the securejoin") @@ -1201,6 +1285,9 @@ class TestOnlineAccount: assert ch.id >= 10 ac1._evtracker.wait_securejoin_inviter_progress(1000) + ac1.shutdown() + ac2.shutdown() + def test_qr_join_chat(self, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() lp.sec("ac1: create QR code and let ac2 scan it, starting the securejoin") @@ -1215,6 +1302,9 @@ class TestOnlineAccount: ac2._evtracker.get_matching("DC_EVENT_IMAP_MESSAGE_DELETED") ac1._evtracker.wait_securejoin_inviter_progress(1000) + ac1.shutdown() + ac2.shutdown() + def test_qr_verified_group_and_chatting(self, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() lp.sec("ac1: create verified-group QR, ac2 scans and joins") @@ -1247,6 +1337,9 @@ class TestOnlineAccount: assert msg.text == "world" assert msg.is_encrypted() + ac1.shutdown() + ac2.shutdown() + def test_set_get_contact_avatar(self, acfactory, data, lp): lp.sec("configuring ac1 and ac2") ac1, ac2 = acfactory.get_two_online_accounts() @@ -1294,6 +1387,9 @@ class TestOnlineAccount: msg3 = ac2._evtracker.wait_next_incoming_message() assert msg3.get_sender_contact().get_profile_image() is None + ac1.shutdown() + ac2.shutdown() + def test_add_remove_member_remote_events(self, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() ac1_addr = ac1.get_config("addr") @@ -1368,6 +1464,9 @@ class TestOnlineAccount: assert ev.action == "removed" assert ev.message.get_sender_contact().addr == ac1_addr + ac1.shutdown() + ac2.shutdown() + def test_set_get_group_image(self, acfactory, data, lp): ac1, ac2 = acfactory.get_two_online_accounts() @@ -1421,6 +1520,9 @@ class TestOnlineAccount: assert chat1b.get_profile_image() is None assert chat.get_profile_image() is None + ac1.shutdown() + ac2.shutdown() + def test_accept_sender_contact(self, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() ch = ac1.create_chat_by_contact(ac1.create_contact(ac2.get_config("addr"))) @@ -1430,6 +1532,9 @@ class TestOnlineAccount: msg.accept_sender_contact() assert not msg.chat.is_deaddrop() + ac1.shutdown() + ac2.shutdown() + def test_send_receive_locations(self, acfactory, lp): now = datetime.utcnow() ac1, ac2 = acfactory.get_two_online_accounts() @@ -1478,6 +1583,9 @@ class TestOnlineAccount: locations3 = chat2.get_locations(contact=contact) assert not locations3 + ac1.shutdown() + ac2.shutdown() + class TestGroupStressTests: def test_group_many_members_add_leave_remove(self, acfactory, lp): @@ -1485,6 +1593,7 @@ class TestGroupStressTests: accounts = [acfactory.get_online_configuring_account() for i in range(5)] for acc in accounts: acc.wait_configure_finish() + acc.start() ac1 = accounts.pop() lp.sec("ac1: setting up contacts with 4 other members") @@ -1577,6 +1686,12 @@ class TestGroupStressTests: # Message should be encrypted because keys of other members are gossiped assert msg.is_encrypted() + ac1.shutdown() + ac2.shutdown() + ac3.shutdown() + ac4.shutdown() + ac5.shutdown() + def test_synchronize_member_list_on_group_rejoin(self, acfactory, lp): """ Test that user recreates group member list when it joins the group again. @@ -1589,6 +1704,7 @@ class TestGroupStressTests: accounts = [acfactory.get_online_configuring_account() for i in range(3)] for acc in accounts: acc.wait_configure_finish() + acc.start() ac1 = accounts.pop() lp.sec("ac1: setting up contacts with 2 other members") @@ -1650,7 +1766,10 @@ class TestGroupStressTests: msg = ac2._evtracker.wait_next_incoming_message() assert len(msg.chat.get_contacts()) == len(chat.get_contacts()) - + + ac1.shutdown() + ac2.shutdown() + ac3.shutdown() class TestOnlineConfigureFails: def test_invalid_password(self, acfactory): diff --git a/src/configure/mod.rs b/src/configure/mod.rs index 96b21fb9d..619e359a0 100644 --- a/src/configure/mod.rs +++ b/src/configure/mod.rs @@ -83,7 +83,6 @@ impl Context { let mut step_counter: u8 = 0; let (_s, r) = async_std::sync::channel(1); let mut imap = Imap::new(r); - let mut is_imap_connected = false; let was_configured_before = self.is_configured().await; while !self.shall_stop_ongoing().await { @@ -92,7 +91,6 @@ impl Context { match exec_step( self, &mut imap, - &mut is_imap_connected, &mut param, &mut param_domain, &mut param_autoconfig, @@ -117,7 +115,7 @@ impl Context { } } - if is_imap_connected { + if imap.is_connected() { imap.disconnect(self).await; } @@ -171,7 +169,6 @@ impl Context { async fn exec_step( ctx: &Context, imap: &mut Imap, - is_imap_connected: &mut bool, param: &mut LoginParam, param_domain: &mut String, param_autoconfig: &mut Option, @@ -413,8 +410,7 @@ async fn exec_step( progress!(ctx, 600); /* try to connect to IMAP - if we did not got an autoconfig, do some further tries with different settings and username variations */ - *is_imap_connected = - try_imap_connections(ctx, param, param_autoconfig.is_some(), imap).await?; + try_imap_connections(ctx, param, param_autoconfig.is_some(), imap).await?; } 15 => { progress!(ctx, 800);