fix last failing test -- make account.shutdown() robust against getting called from event thread

This commit is contained in:
holger krekel
2020-05-22 15:12:55 +02:00
parent 23ceda5ad9
commit 229606fcc5
3 changed files with 14 additions and 2 deletions

View File

@@ -3,7 +3,7 @@ import pytest
import py
import echo_and_quit
import group_tracking
from deltachat.eventlogger import FFIEventLogger
from deltachat.events import FFIEventLogger
@pytest.fixture(scope='session')
@@ -17,16 +17,23 @@ def datadir():
pytest.skip('test-data directory not found')
def test_echo_quit_plugin(acfactory):
def test_echo_quit_plugin(acfactory, lp):
lp.sec("creating one echo_and_quit bot")
botproc = acfactory.run_bot_process(echo_and_quit)
lp.sec("creating a temp account to contact the bot")
ac1 = acfactory.get_one_online_account()
lp.sec("sending a message to the bot")
bot_contact = ac1.create_contact(botproc.addr)
ch1 = ac1.create_chat_by_contact(bot_contact)
ch1.send_text("hello")
lp.sec("waiting for the bot-reply to arrive")
reply = ac1._evtracker.wait_next_incoming_message()
assert "hello" in reply.text
assert reply.chat == ch1
lp.sec("send quit sequence")
ch1.send_text("/quit")
botproc.wait()

View File

@@ -636,6 +636,7 @@ class Account(object):
self._shutdown_event.set()
hook = hookspec.Global._get_plugin_manager().hook
hook.dc_account_after_shutdown(account=self, dc_context=dc_context)
self.log("shutdown finished")
def _destroy_dc_context(dc_context, dc_context_unref=lib.dc_context_unref):

View File

@@ -147,6 +147,10 @@ class EventThread(threading.Thread):
self._thread_quitflag = True
if wait:
if self == threading.current_thread():
# we are in the callback thread and thus cannot
# wait for the thread-loop to finish.
return
self.join()
def run(self):