mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
fix last failing test -- make account.shutdown() robust against getting called from event thread
This commit is contained in:
@@ -3,7 +3,7 @@ import pytest
|
|||||||
import py
|
import py
|
||||||
import echo_and_quit
|
import echo_and_quit
|
||||||
import group_tracking
|
import group_tracking
|
||||||
from deltachat.eventlogger import FFIEventLogger
|
from deltachat.events import FFIEventLogger
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
@@ -17,16 +17,23 @@ def datadir():
|
|||||||
pytest.skip('test-data directory not found')
|
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)
|
botproc = acfactory.run_bot_process(echo_and_quit)
|
||||||
|
|
||||||
|
lp.sec("creating a temp account to contact the bot")
|
||||||
ac1 = acfactory.get_one_online_account()
|
ac1 = acfactory.get_one_online_account()
|
||||||
|
|
||||||
|
lp.sec("sending a message to the bot")
|
||||||
bot_contact = ac1.create_contact(botproc.addr)
|
bot_contact = ac1.create_contact(botproc.addr)
|
||||||
ch1 = ac1.create_chat_by_contact(bot_contact)
|
ch1 = ac1.create_chat_by_contact(bot_contact)
|
||||||
ch1.send_text("hello")
|
ch1.send_text("hello")
|
||||||
|
|
||||||
|
lp.sec("waiting for the bot-reply to arrive")
|
||||||
reply = ac1._evtracker.wait_next_incoming_message()
|
reply = ac1._evtracker.wait_next_incoming_message()
|
||||||
assert "hello" in reply.text
|
assert "hello" in reply.text
|
||||||
assert reply.chat == ch1
|
assert reply.chat == ch1
|
||||||
|
lp.sec("send quit sequence")
|
||||||
ch1.send_text("/quit")
|
ch1.send_text("/quit")
|
||||||
botproc.wait()
|
botproc.wait()
|
||||||
|
|
||||||
|
|||||||
@@ -636,6 +636,7 @@ class Account(object):
|
|||||||
self._shutdown_event.set()
|
self._shutdown_event.set()
|
||||||
hook = hookspec.Global._get_plugin_manager().hook
|
hook = hookspec.Global._get_plugin_manager().hook
|
||||||
hook.dc_account_after_shutdown(account=self, dc_context=dc_context)
|
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):
|
def _destroy_dc_context(dc_context, dc_context_unref=lib.dc_context_unref):
|
||||||
|
|||||||
@@ -147,6 +147,10 @@ class EventThread(threading.Thread):
|
|||||||
self._thread_quitflag = True
|
self._thread_quitflag = True
|
||||||
|
|
||||||
if wait:
|
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()
|
self.join()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user