mirror of
https://github.com/chatmail/relay.git
synced 2026-05-19 12:28:06 +00:00
test works by logging into remote machine and checking the dovecot quota log
This commit is contained in:
@@ -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