refactor callback thread handling

This commit is contained in:
holger krekel
2020-05-20 16:32:12 +02:00
parent b91d7f314b
commit f67c86cb39
7 changed files with 123 additions and 221 deletions

View File

@@ -1,5 +1,6 @@
from __future__ import print_function
def wait_configuration_progress(account, min_target, max_target=1001, check_error=True):
min_target = min(min_target, max_target)
while 1:

View File

@@ -1686,4 +1686,3 @@ class TestOnlineConfigureFails:
ev = ac1._evtracker.get_matching("DC_EVENT_ERROR_NETWORK")
assert "could not connect" in ev.data2.lower()
wait_configuration_progress(ac1, 0, 0)

View File

@@ -1,7 +1,6 @@
from __future__ import print_function
import threading
import time
from queue import Queue
from deltachat import capi, cutil, const
from deltachat import register_global_plugin
from deltachat.hookspec import global_hookimpl
@@ -10,34 +9,6 @@ from deltachat.capi import lib
# from deltachat.account import EventLogger
class EventThread(threading.Thread):
def __init__(self, dc_context):
self.dc_context = dc_context
super(EventThread, self).__init__()
self.setDaemon(1)
self._running = True
def run(self):
lib.dc_context_run(self.dc_context)
while self._running:
if lib.dc_has_next_event(self.dc_context):
event = lib.dc_get_next_event(self.dc_context)
if event != ffi.NULL:
py_dc_callback(
self._dc_context,
lib.dc_event_get_id(event),
lib.dc_event_get_data1(event),
lib.dc_event_get_data2(event)
)
lib.dc_event_unref(event)
else:
time.sleep(0.05)
def stop(self):
lib.dc_context_shutdown(self.dc_context)
self._running = False
def test_empty_context():
ctx = capi.lib.dc_context_new(capi.ffi.NULL, capi.ffi.NULL)
capi.lib.dc_close(ctx)
@@ -47,33 +18,17 @@ def test_dc_close_events(tmpdir, acfactory):
ac1 = acfactory.get_unconfigured_account()
# register after_shutdown function
shutdowns = []
shutdowns = Queue()
class ShutdownPlugin:
@global_hookimpl
def dc_account_after_shutdown(self, account):
assert account._dc_context is None
shutdowns.append(account)
shutdowns.put(account)
register_global_plugin(ShutdownPlugin())
assert hasattr(ac1, "_dc_context")
ac1.shutdown()
assert shutdowns == [ac1]
def find(info_string):
evlog = ac1._evtracker
while 1:
ev = evlog.get_matching("DC_EVENT_INFO", check_error=False)
data2 = ev.data2
if info_string in data2:
return
else:
print("skipping event", ev)
find("disconnecting inbox-thread")
find("disconnecting sentbox-thread")
find("disconnecting mvbox-thread")
find("disconnecting SMTP")
find("Database closed")
shutdowns.get(timeout=2)
def test_wrong_db(tmpdir):