test works by logging into remote machine and checking the dovecot quota log

This commit is contained in:
holger krekel
2023-10-16 13:46:11 +02:00
committed by missytake
parent c9fd133942
commit 00af333694
2 changed files with 40 additions and 20 deletions

View File

@@ -1,11 +1,11 @@
import os import os
import io import io
import random import random
import subprocess
import imaplib import imaplib
import smtplib import smtplib
import itertools import itertools
import pytest import pytest
import time
@pytest.fixture @pytest.fixture
@@ -84,7 +84,10 @@ class ChatmailTestProcess:
def get_liveconfig_producer(self): def get_liveconfig_producer(self):
while 1: while 1:
user, password = self.gencreds() user, password = self.gencreds()
config = {"addr": user, "mail_pw": password, } config = {
"addr": user,
"mail_pw": password,
}
# speed up account configuration # speed up account configuration
config["mail_server"] = self.maildomain config["mail_server"] = self.maildomain
config["send_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) am.dump_imap_summary(logfile=logfile)
print(logfile.getvalue()) print(logfile.getvalue())
# request.node.add_report_section("call", "imap-server-state", s) # 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

View File

@@ -1,6 +1,5 @@
import random import random
import pytest import pytest
import time
class TestMailSending: class TestMailSending:
@@ -9,13 +8,13 @@ class TestMailSending:
chat = cmfactory.get_accepted_chat(ac1, ac2) chat = cmfactory.get_accepted_chat(ac1, ac2)
lp.sec("ac1: prepare and send text message to 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") lp.sec("wait for ac2 to receive message")
msg2 = ac2._evtracker.wait_next_incoming_message() msg2 = ac2._evtracker.wait_next_incoming_message()
assert msg2.text == "message0" 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) ac1, ac2 = cmfactory.get_online_accounts(2)
chat = cmfactory.get_accepted_chat(ac1, ac2) 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.indent(f"Sent out msg {i}, size {attachsize/(1024*1024)}MB")
lp.sec("ac2: check messages are arriving until quota is reached") lp.sec("ac2: check messages are arriving until quota is reached")
bytes_sent = 0
for i, msg in enumerate(msgs): addr = ac2.get_config("addr").lower()
# wait for the message to be received or to fail saved_ok = 0
start = time.time() for line in dovelogreader():
while time.time() < (start + 30): line = line.decode().lower().strip()
if msg.is_out_delivered(): if addr not in line:
bytes_sent += attachsize # print(line)
mb = bytes_sent // (1024*1024) continue
lp.indent(f"message {i} success, bytes transmitted so far {mb}MB") if "quota" in line:
break if "quota exceeded" in line:
elif msg.is_out_failed(): if saved_ok < num_to_send // 2:
assert i > num_to_send/2, "quota kicked in too early" pytest.fail(
f"quota exceeded too early: after {saved_ok} messages already"
)
lp.indent("good, message sending failed because quota was exceeded") lp.indent("good, message sending failed because quota was exceeded")
lp.indent(chat.get_messages()[i].get_message_info())
return return
else: if "saved mail to inbox" in line:
time.sleep(1) saved_ok += 1
print(f"{saved_ok}: {line}")
if saved_ok >= num_to_send:
break
pytest.fail("sending succeeded although messages should exceed quota") pytest.fail("sending succeeded although messages should exceed quota")