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
 
@@ -258,6 +259,9 @@ def test_postfix_delivery_to_dovecot(host):
 
    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
 
@@ -534,6 +538,9 @@ def test_postfix_local_delivery(host):
 
    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')
 

	
 
@@ -562,6 +569,9 @@ def test_postfix_sends_mails_without_tls_when_unavailable(host):
 
    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')
 

	
 
@@ -590,6 +600,9 @@ def test_postfix_sends_mails_over_tls_when_available(host):
 
    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')
 

	
roles/mail_server/molecule/default/tests/test_optional.py
Show inline comments
 
@@ -57,9 +57,11 @@ def test_local_aliases(host):
 
    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
0 comments (0 inline, 0 general)