mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
refactor "quiet" parameter away and provide more precise logging-control
This commit is contained in:
@@ -42,7 +42,7 @@ def test_group_tracking_plugin(acfactory, lp):
|
|||||||
lp.sec("creating one group-tracking bot and two temp accounts")
|
lp.sec("creating one group-tracking bot and two temp accounts")
|
||||||
botproc = acfactory.run_bot_process(group_tracking, ffi=False)
|
botproc = acfactory.run_bot_process(group_tracking, ffi=False)
|
||||||
|
|
||||||
ac1, ac2 = acfactory.get_two_online_accounts(quiet=True)
|
ac1, ac2 = acfactory.get_two_online_accounts()
|
||||||
|
|
||||||
botproc.fnmatch_lines("""
|
botproc.fnmatch_lines("""
|
||||||
*ac_configure_completed*
|
*ac_configure_completed*
|
||||||
|
|||||||
@@ -29,10 +29,12 @@ class FFIEventLogger:
|
|||||||
# to prevent garbled logging
|
# to prevent garbled logging
|
||||||
_loglock = threading.RLock()
|
_loglock = threading.RLock()
|
||||||
|
|
||||||
def __init__(self, account) -> None:
|
def __init__(self, account, init_time=None) -> None:
|
||||||
self.account = account
|
self.account = account
|
||||||
self.logid = self.account.get_config("displayname")
|
self.logid = self.account.get_config("displayname")
|
||||||
self.init_time = time.time()
|
if init_time is None:
|
||||||
|
init_time = time.time()
|
||||||
|
self.init_time = init_time
|
||||||
|
|
||||||
@account_hookimpl
|
@account_hookimpl
|
||||||
def ac_process_ffi_event(self, ffi_event: FFIEvent) -> None:
|
def ac_process_ffi_event(self, ffi_event: FFIEvent) -> None:
|
||||||
|
|||||||
@@ -244,15 +244,11 @@ class ACFactory:
|
|||||||
assert "addr" in configdict and "mail_pw" in configdict
|
assert "addr" in configdict and "mail_pw" in configdict
|
||||||
return configdict
|
return configdict
|
||||||
|
|
||||||
def get_unconfigured_account(self, quiet=False):
|
def get_unconfigured_account(self):
|
||||||
logid = "ac{}".format(len(self._accounts) + 1)
|
logid = "ac{}".format(len(self._accounts) + 1)
|
||||||
path = self.tmpdir.join(logid)
|
path = self.tmpdir.join(logid)
|
||||||
ac = Account(path.strpath, logging=self._logging)
|
ac = Account(path.strpath, logging=self._logging)
|
||||||
ac._evtracker = ac.add_account_plugin(FFIEventTracker(ac))
|
ac._evtracker = ac.add_account_plugin(FFIEventTracker(ac))
|
||||||
if not quiet:
|
|
||||||
logger = FFIEventLogger(ac)
|
|
||||||
logger.init_time = self.init_time
|
|
||||||
ac.add_account_plugin(logger)
|
|
||||||
self._accounts.append(ac)
|
self._accounts.append(ac)
|
||||||
return ac
|
return ac
|
||||||
|
|
||||||
@@ -291,10 +287,9 @@ class ACFactory:
|
|||||||
self._preconfigure_key(ac, addr)
|
self._preconfigure_key(ac, addr)
|
||||||
return ac
|
return ac
|
||||||
|
|
||||||
def get_online_configuring_account(self, sentbox=False, move=False,
|
def get_online_configuring_account(self, sentbox=False, move=False, config={}):
|
||||||
quiet=False, config={}):
|
|
||||||
configdict = self.get_next_liveconfig()
|
configdict = self.get_next_liveconfig()
|
||||||
ac = self.get_unconfigured_account(quiet=quiet)
|
ac = self.get_unconfigured_account()
|
||||||
configdict.setdefault("displayname", os.path.basename(ac.db_path))
|
configdict.setdefault("displayname", os.path.basename(ac.db_path))
|
||||||
self._preconfigure_key(ac, configdict["addr"])
|
self._preconfigure_key(ac, configdict["addr"])
|
||||||
configdict.update(config)
|
configdict.update(config)
|
||||||
@@ -309,20 +304,17 @@ class ACFactory:
|
|||||||
self.wait_configure_and_start_io()
|
self.wait_configure_and_start_io()
|
||||||
return ac1
|
return ac1
|
||||||
|
|
||||||
def get_two_online_accounts(self, move=False, quiet=False):
|
def get_two_online_accounts(self, move=False):
|
||||||
ac1 = self.get_online_configuring_account(move=move, quiet=quiet)
|
ac1 = self.get_online_configuring_account(move=move)
|
||||||
ac2 = self.get_online_configuring_account(quiet=quiet)
|
ac2 = self.get_online_configuring_account()
|
||||||
self.wait_configure_and_start_io()
|
self.wait_configure_and_start_io()
|
||||||
return ac1, ac2
|
return ac1, ac2
|
||||||
|
|
||||||
def get_many_online_accounts(self, num, move=True):
|
def get_many_online_accounts(self, num, move=True):
|
||||||
accounts = [self.get_online_configuring_account(move=move, quiet=True)
|
# to reduce number of log events for higher level tests
|
||||||
for i in range(num)]
|
# logging only starts after initial successful configuration
|
||||||
self.wait_configure_and_start_io()
|
accounts = [self.get_online_configuring_account(move=move) for i in range(num)]
|
||||||
# to reduce logging for higher level tests, logging only starts
|
self.wait_configure_and_start_io(logstart="after_inbox_idle_ready")
|
||||||
# after initial successful configuration
|
|
||||||
for acc in accounts:
|
|
||||||
acc.add_account_plugin(FFIEventLogger(acc))
|
|
||||||
return accounts
|
return accounts
|
||||||
|
|
||||||
def clone_online_account(self, account):
|
def clone_online_account(self, account):
|
||||||
@@ -346,8 +338,11 @@ class ACFactory:
|
|||||||
ac._configtracker = ac.configure()
|
ac._configtracker = ac.configure()
|
||||||
return ac
|
return ac
|
||||||
|
|
||||||
def wait_configure_and_start_io(self):
|
def wait_configure_and_start_io(self, logstart="after_inbox_idle_ready"):
|
||||||
|
assert logstart in ("after_inbox_idle_ready",), logstart
|
||||||
|
|
||||||
for acc in self._accounts:
|
for acc in self._accounts:
|
||||||
|
logger = FFIEventLogger(acc, init_time=self.init_time)
|
||||||
self.wait_configure(acc)
|
self.wait_configure(acc)
|
||||||
acc.set_config("bcc_self", "0")
|
acc.set_config("bcc_self", "0")
|
||||||
acc.start_io()
|
acc.start_io()
|
||||||
@@ -356,6 +351,8 @@ class ACFactory:
|
|||||||
acc._evtracker.wait_idle_inbox_ready()
|
acc._evtracker.wait_idle_inbox_ready()
|
||||||
print("{}: {} account IMAP IO ready to receive".format(
|
print("{}: {} account IMAP IO ready to receive".format(
|
||||||
acc.get_config("displayname"), acc.get_config("addr")))
|
acc.get_config("displayname"), acc.get_config("addr")))
|
||||||
|
if logstart == "after_inbox_idle_ready":
|
||||||
|
acc.add_account_plugin(logger)
|
||||||
|
|
||||||
def wait_configure(self, acc):
|
def wait_configure(self, acc):
|
||||||
if hasattr(acc, "_configtracker"):
|
if hasattr(acc, "_configtracker"):
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ def test_db_busy_error(acfactory, tmpdir):
|
|||||||
print("%3.2f %s" % (time.time() - starttime, string))
|
print("%3.2f %s" % (time.time() - starttime, string))
|
||||||
|
|
||||||
# make a number of accounts
|
# make a number of accounts
|
||||||
accounts = acfactory.get_many_online_accounts(3, quiet=True)
|
accounts = acfactory.get_many_online_accounts(3)
|
||||||
log("created %s accounts" % len(accounts))
|
log("created %s accounts" % len(accounts))
|
||||||
|
|
||||||
# put a bigfile into each account
|
# put a bigfile into each account
|
||||||
|
|||||||
Reference in New Issue
Block a user