mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 15:26:30 +03:00
snap
This commit is contained in:
@@ -46,7 +46,6 @@ class Account(object):
|
|||||||
lib.dc_context_new(lib.py_dc_callback, ffi.NULL, as_dc_charpointer(os_name)),
|
lib.dc_context_new(lib.py_dc_callback, ffi.NULL, as_dc_charpointer(os_name)),
|
||||||
_destroy_dc_context,
|
_destroy_dc_context,
|
||||||
)
|
)
|
||||||
|
|
||||||
hook = hookspec.Global._get_plugin_manager().hook
|
hook = hookspec.Global._get_plugin_manager().hook
|
||||||
|
|
||||||
self._threads = iothreads.IOThreads(self)
|
self._threads = iothreads.IOThreads(self)
|
||||||
@@ -55,9 +54,9 @@ class Account(object):
|
|||||||
self._shutdown_event = Event()
|
self._shutdown_event = Event()
|
||||||
|
|
||||||
# open database
|
# open database
|
||||||
self.db_path = db_path
|
|
||||||
if hasattr(db_path, "encode"):
|
if hasattr(db_path, "encode"):
|
||||||
db_path = db_path.encode("utf8")
|
db_path = db_path.encode("utf8")
|
||||||
|
self.db_path = db_path
|
||||||
if not lib.dc_open(self._dc_context, db_path, ffi.NULL):
|
if not lib.dc_open(self._dc_context, db_path, ffi.NULL):
|
||||||
raise ValueError("Could not dc_open: {}".format(db_path))
|
raise ValueError("Could not dc_open: {}".format(db_path))
|
||||||
self._configkeys = self.get_config("sys.config_keys").split()
|
self._configkeys = self.get_config("sys.config_keys").split()
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ from . import Account, const
|
|||||||
from .tracker import ConfigureTracker
|
from .tracker import ConfigureTracker
|
||||||
from .capi import lib
|
from .capi import lib
|
||||||
from .eventlogger import FFIEventLogger, FFIEventTracker
|
from .eventlogger import FFIEventLogger, FFIEventTracker
|
||||||
from _pytest.monkeypatch import MonkeyPatch
|
|
||||||
from _pytest._code import Source
|
from _pytest._code import Source
|
||||||
|
|
||||||
import deltachat
|
import deltachat
|
||||||
@@ -99,14 +98,11 @@ def pytest_report_header(config, startdir):
|
|||||||
summary = []
|
summary = []
|
||||||
|
|
||||||
t = tempfile.mktemp()
|
t = tempfile.mktemp()
|
||||||
m = MonkeyPatch()
|
|
||||||
try:
|
try:
|
||||||
m.setattr(sys.stdout, "write", lambda x: len(x))
|
ac = Account(t, logging=True)
|
||||||
ac = Account(t)
|
|
||||||
info = ac.get_info()
|
info = ac.get_info()
|
||||||
ac.shutdown()
|
ac.shutdown(False)
|
||||||
finally:
|
finally:
|
||||||
m.undo()
|
|
||||||
os.remove(t)
|
os.remove(t)
|
||||||
summary.extend(['Deltachat core={} sqlite={}'.format(
|
summary.extend(['Deltachat core={} sqlite={}'.format(
|
||||||
info['deltachat_core_version'],
|
info['deltachat_core_version'],
|
||||||
|
|||||||
@@ -1,18 +1,23 @@
|
|||||||
|
|
||||||
import time
|
import time
|
||||||
|
import threading
|
||||||
|
import pytest
|
||||||
import os
|
import os
|
||||||
from queue import Queue
|
from queue import Queue, Empty
|
||||||
|
|
||||||
import deltachat
|
import deltachat
|
||||||
|
|
||||||
|
|
||||||
def test_db_busy_error(acfactory, tmpdir):
|
def test_db_busy_error(acfactory, tmpdir):
|
||||||
starttime = time.time()
|
starttime = time.time()
|
||||||
|
log_lock = threading.RLock()
|
||||||
|
|
||||||
def log(string):
|
def log(string):
|
||||||
print("%3.2f %s" % (time.time() - starttime, string))
|
with log_lock:
|
||||||
|
print("%3.2f %s" % (time.time() - starttime, string))
|
||||||
|
|
||||||
# make a number of accounts
|
# make a number of accounts
|
||||||
accounts = acfactory.get_many_online_accounts(5, quiet=False)
|
accounts = acfactory.get_many_online_accounts(5, quiet=True)
|
||||||
log("created %s accounts" % len(accounts))
|
log("created %s accounts" % len(accounts))
|
||||||
|
|
||||||
# put a bigfile into each account
|
# put a bigfile into each account
|
||||||
@@ -36,7 +41,7 @@ def test_db_busy_error(acfactory, tmpdir):
|
|||||||
# each replier receives all events and sends report events to receive_queue
|
# each replier receives all events and sends report events to receive_queue
|
||||||
repliers = []
|
repliers = []
|
||||||
for acc in accounts:
|
for acc in accounts:
|
||||||
replier = AutoReplier(acc, num_send=1000, num_bigfiles=0, report_func=report_func)
|
replier = AutoReplier(acc, log=log, num_send=1000, num_bigfiles=0, report_func=report_func)
|
||||||
acc.add_account_plugin(replier)
|
acc.add_account_plugin(replier)
|
||||||
repliers.append(replier)
|
repliers.append(replier)
|
||||||
|
|
||||||
@@ -46,37 +51,59 @@ def test_db_busy_error(acfactory, tmpdir):
|
|||||||
|
|
||||||
alive_count = len(accounts)
|
alive_count = len(accounts)
|
||||||
while alive_count > 0:
|
while alive_count > 0:
|
||||||
replier, report_type, report_args = report_queue.get(10)
|
try:
|
||||||
addr = replier.account.get_self_contact().addr
|
replier, report_type, report_args = report_queue.get(timeout=10)
|
||||||
assert addr
|
except Empty:
|
||||||
|
log("timeout waiting for next event")
|
||||||
|
pytest.fail("timeout exceeded")
|
||||||
if report_type == ReportType.exit:
|
if report_type == ReportType.exit:
|
||||||
alive_count -= 1
|
replier.log("EXIT".format(alive_count))
|
||||||
log("{} EXIT -- remaining: {}".format(addr, alive_count))
|
|
||||||
replier.account.shutdown(wait=True)
|
|
||||||
elif report_type == ReportType.message_sent:
|
|
||||||
log("{} sent message: {}".format(addr, report_args[0].text))
|
|
||||||
elif report_type == ReportType.message_incoming:
|
|
||||||
log("{} incoming message: {}".format(addr, report_args[0].text))
|
|
||||||
elif report_type == ReportType.ffi_error:
|
elif report_type == ReportType.ffi_error:
|
||||||
log("{} ERROR: {}".format(addr, report_args[0]))
|
replier.log("ERROR: {}".format(addr, report_args[0]))
|
||||||
replier.account.shutdown(wait=True)
|
elif report_type == ReportType.message_echo:
|
||||||
alive_count -= 1
|
continue
|
||||||
|
else:
|
||||||
|
raise ValueError("{} unknown report type {}, args={}".format(
|
||||||
|
addr, report_type, report_args
|
||||||
|
))
|
||||||
|
alive_count -= 1
|
||||||
|
replier.log("shutting down")
|
||||||
|
replier.account.shutdown(wait=False)
|
||||||
|
replier.log("shut down complete, remaining={}".format(alive_count))
|
||||||
|
|
||||||
|
|
||||||
class ReportType:
|
class ReportType:
|
||||||
exit = "exit"
|
exit = "exit"
|
||||||
message_sent = "message-sent"
|
|
||||||
ffi_error = "ffi-error"
|
ffi_error = "ffi-error"
|
||||||
message_incoming = "message-incoming"
|
message_echo = "message-echo"
|
||||||
|
|
||||||
|
|
||||||
class AutoReplier:
|
class AutoReplier:
|
||||||
def __init__(self, account, report_func, num_send, num_bigfiles):
|
def __init__(self, account, log, num_send, num_bigfiles, report_func):
|
||||||
self.account = account
|
self.account = account
|
||||||
|
self._log = log
|
||||||
self.report_func = report_func
|
self.report_func = report_func
|
||||||
self.num_send = num_send
|
self.num_send = num_send
|
||||||
self.num_bigfiles = num_bigfiles
|
self.num_bigfiles = num_bigfiles
|
||||||
self.current_sent = 0
|
self.current_sent = 0
|
||||||
|
self.addr = self.account.get_self_contact().addr
|
||||||
|
|
||||||
|
self._thread = threading.Thread(
|
||||||
|
name="Stats{}".format(self.account),
|
||||||
|
target=self.thread_stats
|
||||||
|
)
|
||||||
|
self._thread.setDaemon(True)
|
||||||
|
self._thread.start()
|
||||||
|
|
||||||
|
def log(self, message):
|
||||||
|
self._log("{} {}".format(self.addr, message))
|
||||||
|
|
||||||
|
def thread_stats(self):
|
||||||
|
# XXX later use, for now we just quit
|
||||||
|
return
|
||||||
|
while 1:
|
||||||
|
time.sleep(1.0)
|
||||||
|
break
|
||||||
|
|
||||||
@deltachat.account_hookimpl
|
@deltachat.account_hookimpl
|
||||||
def ac_incoming_message(self, message):
|
def ac_incoming_message(self, message):
|
||||||
@@ -84,7 +111,7 @@ class AutoReplier:
|
|||||||
return
|
return
|
||||||
message.accept_sender_contact()
|
message.accept_sender_contact()
|
||||||
message.mark_seen()
|
message.mark_seen()
|
||||||
self.report_func(self, ReportType.message_incoming, message)
|
self.log("incoming message: {}".format(message))
|
||||||
|
|
||||||
self.current_sent += 1
|
self.current_sent += 1
|
||||||
# we are still alive, let's send a reply
|
# we are still alive, let's send a reply
|
||||||
@@ -94,12 +121,14 @@ class AutoReplier:
|
|||||||
else:
|
else:
|
||||||
msg = message.chat.send_text("got message id {}, small text reply".format(message.id))
|
msg = message.chat.send_text("got message id {}, small text reply".format(message.id))
|
||||||
assert msg.text
|
assert msg.text
|
||||||
self.report_func(self, ReportType.message_sent, msg)
|
self.log("message-sent: {}".format(msg))
|
||||||
|
self.report_func(self, ReportType.message_echo)
|
||||||
if self.current_sent >= self.num_send:
|
if self.current_sent >= self.num_send:
|
||||||
self.report_func(self, ReportType.exit)
|
self.report_func(self, ReportType.exit)
|
||||||
return
|
return
|
||||||
|
|
||||||
@deltachat.account_hookimpl
|
@deltachat.account_hookimpl
|
||||||
def ac_process_ffi_event(self, ffi_event):
|
def ac_process_ffi_event(self, ffi_event):
|
||||||
|
self.log(ffi_event)
|
||||||
if ffi_event.name == "DC_EVENT_ERROR":
|
if ffi_event.name == "DC_EVENT_ERROR":
|
||||||
self.report_func(self, ReportType.ffi_error, ffi_event)
|
self.report_func(self, ReportType.ffi_error, ffi_event)
|
||||||
|
|||||||
Reference in New Issue
Block a user