mirror of
https://github.com/chatmail/relay.git
synced 2026-05-12 00:54:37 +00:00
test works by logging into remote machine and checking the dovecot quota log
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import os
|
||||
import io
|
||||
import random
|
||||
import subprocess
|
||||
import imaplib
|
||||
import smtplib
|
||||
import itertools
|
||||
import pytest
|
||||
import time
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -84,7 +84,10 @@ class ChatmailTestProcess:
|
||||
def get_liveconfig_producer(self):
|
||||
while 1:
|
||||
user, password = self.gencreds()
|
||||
config = {"addr": user, "mail_pw": password, }
|
||||
config = {
|
||||
"addr": user,
|
||||
"mail_pw": password,
|
||||
}
|
||||
# speed up account configuration
|
||||
config["mail_server"] = self.maildomain
|
||||
config["send_server"] = self.maildomain
|
||||
@@ -112,3 +115,16 @@ def cmfactory(request, maildomain, gencreds, tmpdir, data):
|
||||
am.dump_imap_summary(logfile=logfile)
|
||||
print(logfile.getvalue())
|
||||
# request.node.add_report_section("call", "imap-server-state", s)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dovelogreader(maildomain):
|
||||
def remote_reader():
|
||||
popen = subprocess.Popen(
|
||||
["ssh", f"root@{maildomain}", "journalctl -f -u dovecot"],
|
||||
stdout=subprocess.PIPE,
|
||||
)
|
||||
while 1:
|
||||
yield popen.stdout.readline()
|
||||
|
||||
return remote_reader
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import random
|
||||
import pytest
|
||||
import time
|
||||
|
||||
|
||||
class TestMailSending:
|
||||
@@ -9,13 +8,13 @@ class TestMailSending:
|
||||
chat = cmfactory.get_accepted_chat(ac1, ac2)
|
||||
|
||||
lp.sec("ac1: prepare and send text message to ac2")
|
||||
msg1 = chat.send_text("message0")
|
||||
chat.send_text("message0")
|
||||
|
||||
lp.sec("wait for ac2 to receive message")
|
||||
msg2 = ac2._evtracker.wait_next_incoming_message()
|
||||
assert msg2.text == "message0"
|
||||
|
||||
def test_exceed_quota(self, cmfactory, lp, tmpdir):
|
||||
def test_exceed_quota(self, cmfactory, lp, tmpdir, dovelogreader):
|
||||
ac1, ac2 = cmfactory.get_online_accounts(2)
|
||||
chat = cmfactory.get_accepted_chat(ac1, ac2)
|
||||
|
||||
@@ -38,21 +37,26 @@ class TestMailSending:
|
||||
lp.indent(f"Sent out msg {i}, size {attachsize/(1024*1024)}MB")
|
||||
|
||||
lp.sec("ac2: check messages are arriving until quota is reached")
|
||||
bytes_sent = 0
|
||||
for i, msg in enumerate(msgs):
|
||||
# wait for the message to be received or to fail
|
||||
start = time.time()
|
||||
while time.time() < (start + 30):
|
||||
if msg.is_out_delivered():
|
||||
bytes_sent += attachsize
|
||||
mb = bytes_sent // (1024*1024)
|
||||
lp.indent(f"message {i} success, bytes transmitted so far {mb}MB")
|
||||
break
|
||||
elif msg.is_out_failed():
|
||||
assert i > num_to_send/2, "quota kicked in too early"
|
||||
|
||||
addr = ac2.get_config("addr").lower()
|
||||
saved_ok = 0
|
||||
for line in dovelogreader():
|
||||
line = line.decode().lower().strip()
|
||||
if addr not in line:
|
||||
# print(line)
|
||||
continue
|
||||
if "quota" in line:
|
||||
if "quota exceeded" in line:
|
||||
if saved_ok < num_to_send // 2:
|
||||
pytest.fail(
|
||||
f"quota exceeded too early: after {saved_ok} messages already"
|
||||
)
|
||||
lp.indent("good, message sending failed because quota was exceeded")
|
||||
lp.indent(chat.get_messages()[i].get_message_info())
|
||||
return
|
||||
else:
|
||||
time.sleep(1)
|
||||
if "saved mail to inbox" in line:
|
||||
saved_ok += 1
|
||||
print(f"{saved_ok}: {line}")
|
||||
if saved_ok >= num_to_send:
|
||||
break
|
||||
|
||||
pytest.fail("sending succeeded although messages should exceed quota")
|
||||
|
||||
Reference in New Issue
Block a user