with help/side-comments from alex i fixed the concurrent account creation problem
This commit is contained in:
parent
43c02377ef
commit
bbf2f0dd36
@ -15,6 +15,9 @@ filtermail = "chatmaild.filtermail:main"
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
addopts = "-v -ra --strict-markers"
|
||||
log_format = "%(asctime)s %(levelname)s %(message)s"
|
||||
log_date_format = "%Y-%m-%d %H:%M:%S"
|
||||
log_level = "INFO"
|
||||
|
||||
[tool.tox]
|
||||
legacy_tox_ini = """
|
||||
|
@ -116,7 +116,7 @@ def handle_dovecot_request(msg, db, mail_domain):
|
||||
|
||||
|
||||
class ThreadedUnixStreamServer(ThreadingMixIn, UnixStreamServer):
|
||||
pass
|
||||
request_queue_size = 100
|
||||
|
||||
|
||||
def main():
|
||||
@ -128,14 +128,20 @@ def main():
|
||||
|
||||
class Handler(StreamRequestHandler):
|
||||
def handle(self):
|
||||
while True:
|
||||
msg = self.rfile.readline().strip().decode()
|
||||
if not msg:
|
||||
break
|
||||
res = handle_dovecot_request(msg, db, mail_domain)
|
||||
if res:
|
||||
self.wfile.write(res.encode("ascii"))
|
||||
self.wfile.flush()
|
||||
try:
|
||||
while True:
|
||||
msg = self.rfile.readline().strip().decode()
|
||||
if not msg:
|
||||
break
|
||||
res = handle_dovecot_request(msg, db, mail_domain)
|
||||
if res:
|
||||
self.wfile.write(res.encode("ascii"))
|
||||
self.wfile.flush()
|
||||
else:
|
||||
logging.warn("request had no answer: %r", msg)
|
||||
except Exception:
|
||||
logging.exception()
|
||||
raise
|
||||
|
||||
try:
|
||||
os.unlink(socket)
|
||||
|
@ -1,5 +1,5 @@
|
||||
import json
|
||||
|
||||
import sys
|
||||
import pytest
|
||||
import threading
|
||||
import queue
|
||||
@ -60,27 +60,31 @@ def test_handle_dovecot_request(db):
|
||||
assert userdata["password"].startswith("{SHA512-CRYPT}")
|
||||
|
||||
|
||||
def test_100_concurrent_lookups(db):
|
||||
num = 100
|
||||
dbs = [Database(db.path) for i in range(num)]
|
||||
print(f"created {num} databases")
|
||||
def test_100_concurrent_lookups_different_accounts(db, gencreds):
|
||||
num_threads = 100
|
||||
req_per_thread = 5
|
||||
results = queue.Queue()
|
||||
|
||||
def lookup(db):
|
||||
try:
|
||||
lookup_passdb(db, "something@c1.testrun.org", "Pieg9aeToe3eghuthe5u")
|
||||
except Exception:
|
||||
results.put(traceback.format_exc())
|
||||
else:
|
||||
results.put(None)
|
||||
for i in range(req_per_thread):
|
||||
addr, password = gencreds()
|
||||
try:
|
||||
lookup_passdb(db, addr, password)
|
||||
except Exception:
|
||||
results.put(traceback.format_exc())
|
||||
else:
|
||||
results.put(None)
|
||||
|
||||
threads = [threading.Thread(target=lookup, args=(db,), daemon=True) for db in dbs]
|
||||
threads = []
|
||||
for i in range(num_threads):
|
||||
thread = threading.Thread(target=lookup, args=(db,), daemon=True)
|
||||
threads.append(thread)
|
||||
|
||||
print(f"created {num} threads, starting them and waiting for results")
|
||||
print(f"created {num_threads} threads, starting them and waiting for results")
|
||||
for thread in threads:
|
||||
thread.start()
|
||||
|
||||
for _ in dbs:
|
||||
for i in range(num_threads * req_per_thread):
|
||||
res = results.get()
|
||||
if res is not None:
|
||||
pytest.fail(f"concurrent lookup failed\n{res}")
|
||||
|
Loading…
Reference in New Issue
Block a user