Changeset - 8902cd5aa66b
[Not reviewed]
0 2 0
Branko Majic (branko) - 13 days ago 2024-09-06 15:02:01
branko@majic.rs
MAR-218: Improve mail server role test reliability:

- Introduce sleep after sending out mails in order to ensure that
Postfix has had enough time to process the messages.
- Relevant only for tests that take care of parsing the mail log.
- Solves the false negatives caused by timing issues.
- It might be a good idea down the line to implement some kind of
retry/backoff mechanism instead.
2 files changed with 16 insertions and 1 deletions:
0 comments (0 inline, 0 general)
roles/mail_server/molecule/default/tests/test_default.py
Show inline comments
 
import os
 
import re
 
import time
 
import uuid
 

	
 
import defusedxml.ElementTree as ElementTree
 

	
 
import testinfra.utils.ansible_runner
 

	
 
@@ -255,12 +256,15 @@ def test_postfix_delivery_to_dovecot(host):
 
    message_id = "%s@localhost" % str(uuid.uuid4())
 

	
 
    # Virtual account.
 
    send = host.run('swaks --header %s --suppress-data --to john.doe@domain1 --server %s', "Message-Id: <%s>" % message_id, hostname)
 
    assert send.rc == 0
 

	
 
    # Wait for a little while for message to be processed.
 
    time.sleep(5)
 

	
 
    with host.sudo():
 
        mail_log = host.file('/var/log/mail.log')
 
        pattern = r"dovecot: lda\(john.doe@domain1\)<\d+><.+?>: msgid=<%s>: saved mail to INBOX" % message_id
 
        assert re.search(pattern, mail_log.content_string) is not None
 

	
 

	
 
@@ -531,12 +535,15 @@ def test_postfix_local_delivery(host):
 

	
 
    message_id = "%s@localhost" % str(uuid.uuid4())
 

	
 
    send = host.run('swaks --header %s --suppress-data --to localuser@localhost --server localhost', "Message-Id: <%s>" % message_id)
 
    assert send.rc == 0
 

	
 
    # Wait for a little while for message to be processed.
 
    time.sleep(5)
 

	
 
    with host.sudo():
 
        mail_log = host.file('/var/log/mail.log')
 

	
 
        pattern = r"postfix/cleanup\[\d+\]: (?P<queue_id>[^:]+): message-id=<%s>" % message_id
 
        match_result = re.search(pattern, mail_log.content_string)
 
        assert match_result is not None
 
@@ -559,12 +566,15 @@ def test_postfix_sends_mails_without_tls_when_unavailable(host):
 
    assert "Host did not advertise STARTTLS" in send.stderr
 

	
 
    message_id = "%s@localhost" % str(uuid.uuid4())
 
    send = host.run('swaks --header %s --suppress-data --to root@smtp-server-refusing-tls --server localhost', "Message-Id: <%s>" % message_id)
 
    assert send.rc == 0
 

	
 
    # Wait for a little while for message to be processed.
 
    time.sleep(5)
 

	
 
    with host.sudo():
 
        mail_log = host.file('/var/log/mail.log')
 

	
 
        pattern = r"postfix/cleanup\[\d+\]: (?P<queue_id>[^:]+): message-id=<%s>" % message_id
 
        match_result = re.search(pattern, mail_log.content_string)
 
        assert match_result is not None
 
@@ -587,12 +597,15 @@ def test_postfix_sends_mails_over_tls_when_available(host):
 
    assert "Must issue a STARTTLS command first" in send.stdout
 

	
 
    message_id = "%s@localhost" % str(uuid.uuid4())
 
    send = host.run('swaks --tls --header %s --suppress-data --to root@smtp-server-requiring-tls --server localhost', "Message-Id: <%s>" % message_id)
 
    assert send.rc == 0
 

	
 
    # Wait for a little while for message to be processed.
 
    time.sleep(5)
 

	
 
    with host.sudo():
 
        mail_log = host.file('/var/log/mail.log')
 

	
 
        pattern = r"postfix/cleanup\[\d+\]: (?P<queue_id>[^:]+): message-id=<%s>" % message_id
 
        match_result = re.search(pattern, mail_log.content_string)
 
        assert match_result is not None
roles/mail_server/molecule/default/tests/test_optional.py
Show inline comments
 
@@ -54,15 +54,17 @@ def test_local_aliases(host):
 
    Tests if local aliases are configured correctly.
 
    """
 

	
 
    message_id = "%s@localhost" % str(uuid.uuid4())
 

	
 
    send = host.run('swaks --header %s --suppress-data --to root@localhost', "Message-Id: <%s>" % message_id)
 
    time.sleep(1)
 
    assert send.rc == 0
 

	
 
    # Wait for a little while for message to be processed.
 
    time.sleep(5)
 

	
 
    with host.sudo():
 
        mail_log = host.file('/var/log/mail.log')
 
        pattern = r"dovecot: lda\(john.doe@domain1\)<\d+><.+?>: msgid=<%s>: saved mail to INBOX" % message_id
 
        assert re.search(pattern, mail_log.content_string) is not None
 

	
 

	
0 comments (0 inline, 0 general)