mirror of
https://github.com/chatmail/relay.git
synced 2026-05-10 16:04:37 +00:00
with help/side-comments from alex i fixed the concurrent account creation problem
This commit is contained in:
@@ -15,6 +15,9 @@ filtermail = "chatmaild.filtermail:main"
|
|||||||
|
|
||||||
[tool.pytest.ini_options]
|
[tool.pytest.ini_options]
|
||||||
addopts = "-v -ra --strict-markers"
|
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]
|
[tool.tox]
|
||||||
legacy_tox_ini = """
|
legacy_tox_ini = """
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ def handle_dovecot_request(msg, db, mail_domain):
|
|||||||
|
|
||||||
|
|
||||||
class ThreadedUnixStreamServer(ThreadingMixIn, UnixStreamServer):
|
class ThreadedUnixStreamServer(ThreadingMixIn, UnixStreamServer):
|
||||||
pass
|
request_queue_size = 100
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -128,14 +128,20 @@ def main():
|
|||||||
|
|
||||||
class Handler(StreamRequestHandler):
|
class Handler(StreamRequestHandler):
|
||||||
def handle(self):
|
def handle(self):
|
||||||
while True:
|
try:
|
||||||
msg = self.rfile.readline().strip().decode()
|
while True:
|
||||||
if not msg:
|
msg = self.rfile.readline().strip().decode()
|
||||||
break
|
if not msg:
|
||||||
res = handle_dovecot_request(msg, db, mail_domain)
|
break
|
||||||
if res:
|
res = handle_dovecot_request(msg, db, mail_domain)
|
||||||
self.wfile.write(res.encode("ascii"))
|
if res:
|
||||||
self.wfile.flush()
|
self.wfile.write(res.encode("ascii"))
|
||||||
|
self.wfile.flush()
|
||||||
|
else:
|
||||||
|
logging.warn("request had no answer: %r", msg)
|
||||||
|
except Exception:
|
||||||
|
logging.exception()
|
||||||
|
raise
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.unlink(socket)
|
os.unlink(socket)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
import pytest
|
import pytest
|
||||||
import threading
|
import threading
|
||||||
import queue
|
import queue
|
||||||
@@ -60,27 +60,31 @@ def test_handle_dovecot_request(db):
|
|||||||
assert userdata["password"].startswith("{SHA512-CRYPT}")
|
assert userdata["password"].startswith("{SHA512-CRYPT}")
|
||||||
|
|
||||||
|
|
||||||
def test_100_concurrent_lookups(db):
|
def test_100_concurrent_lookups_different_accounts(db, gencreds):
|
||||||
num = 100
|
num_threads = 100
|
||||||
dbs = [Database(db.path) for i in range(num)]
|
req_per_thread = 5
|
||||||
print(f"created {num} databases")
|
|
||||||
results = queue.Queue()
|
results = queue.Queue()
|
||||||
|
|
||||||
def lookup(db):
|
def lookup(db):
|
||||||
try:
|
for i in range(req_per_thread):
|
||||||
lookup_passdb(db, "something@c1.testrun.org", "Pieg9aeToe3eghuthe5u")
|
addr, password = gencreds()
|
||||||
except Exception:
|
try:
|
||||||
results.put(traceback.format_exc())
|
lookup_passdb(db, addr, password)
|
||||||
else:
|
except Exception:
|
||||||
results.put(None)
|
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:
|
for thread in threads:
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
for _ in dbs:
|
for i in range(num_threads * req_per_thread):
|
||||||
res = results.get()
|
res = results.get()
|
||||||
if res is not None:
|
if res is not None:
|
||||||
pytest.fail(f"concurrent lookup failed\n{res}")
|
pytest.fail(f"concurrent lookup failed\n{res}")
|
||||||
|
|||||||
Reference in New Issue
Block a user