try add a little testing of imex events

This commit is contained in:
holger krekel
2020-10-19 18:48:55 +02:00
parent 8aaea09011
commit ff34ed6054
2 changed files with 28 additions and 3 deletions

View File

@@ -20,6 +20,14 @@ class ImexTracker:
elif ffi_event.name == "DC_EVENT_IMEX_FILE_WRITTEN": elif ffi_event.name == "DC_EVENT_IMEX_FILE_WRITTEN":
self._imex_events.put(ffi_event.data2) self._imex_events.put(ffi_event.data2)
def wait_progress(self, target_progress, progress_timeout=60):
while True:
ev = self._imex_events.get(timeout=progress_timeout)
if isinstance(ev, int) and ev >= target_progress:
return ev
if ev == 1000 or ev == 0:
return None
def wait_finish(self, progress_timeout=60): def wait_finish(self, progress_timeout=60):
""" Return list of written files, raise ValueError if ExportFailed. """ """ Return list of written files, raise ValueError if ExportFailed. """
files_written = [] files_written = []

View File

@@ -6,6 +6,7 @@ import queue
import time import time
from deltachat import const, Account from deltachat import const, Account
from deltachat.message import Message from deltachat.message import Message
from deltachat.tracker import ImexTracker
from deltachat.hookspec import account_hookimpl from deltachat.hookspec import account_hookimpl
from datetime import datetime, timedelta from datetime import datetime, timedelta
@@ -1245,8 +1246,16 @@ class TestOnlineAccount:
backupdir = tmpdir.mkdir("backup") backupdir = tmpdir.mkdir("backup")
lp.sec("export all to {}".format(backupdir)) lp.sec("export all to {}".format(backupdir))
path = ac1.export_all(backupdir.strpath) with ac1.temp_plugin(ImexTracker()) as imex_tracker:
assert os.path.exists(path) path = ac1.export_all(backupdir.strpath)
assert os.path.exists(path)
# check progress events for export
imex_tracker.wait_progress(250)
imex_tracker.wait_progress(500)
imex_tracker.wait_progress(750)
imex_tracker.wait_progress(1000)
# return mex_tracker.wait_finish()
t = time.time() t = time.time()
lp.sec("get fresh empty account") lp.sec("get fresh empty account")
@@ -1257,7 +1266,15 @@ class TestOnlineAccount:
assert path2 == path assert path2 == path
lp.sec("import backup and check it's proper") lp.sec("import backup and check it's proper")
ac2.import_all(path) with ac2.temp_plugin(ImexTracker()) as imex_tracker:
ac2.import_all(path)
# check progress events for import
imex_tracker.wait_progress(250)
imex_tracker.wait_progress(500)
imex_tracker.wait_progress(750)
imex_tracker.wait_progress(1000)
contacts = ac2.get_contacts(query="some1") contacts = ac2.get_contacts(query="some1")
assert len(contacts) == 1 assert len(contacts) == 1
contact2 = contacts[0] contact2 = contacts[0]