Fix timing dependent failures

This commit is contained in:
Martin Schulze 2020-10-20 13:48:16 +02:00
parent 1bd1fd3b32
commit 5cce70b3a9
2 changed files with 19 additions and 37 deletions

View file

@ -4,16 +4,7 @@ load 'test_helper/common'
# ---------
# When SPAMASSASSIN_SPAM_TO_INBOX=1, spam messages must be delivered and eventually (MOVE_SPAM_TO_JUNK=1) moved to the Junk folder.
function setup() {
run_setup_file_if_necessary
}
function teardown() {
run_teardown_file_if_necessary
}
function setup_file() {
@test "checking amavis: spam message is delivered and moved to the Junk folder (MOVE_SPAM_TO_JUNK=1)" {
local PRIVATE_CONFIG
PRIVATE_CONFIG="$(duplicate_config_for_container . mail_spam_moved_junk)"
docker run -d --name mail_spam_moved_junk \
@ -25,31 +16,10 @@ function setup_file() {
-e SA_SPAM_SUBJECT="SPAM: " \
-h mail.my-domain.com -t "${NAME}"
wait_for_finished_setup_in_container mail_spam_moved_junk
teardown() { docker rm -f mail_spam_moved_junk; }
PRIVATE_CONFIG="$(duplicate_config_for_container . mail_spam_moved_new)"
docker run -d --name mail_spam_moved_new \
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
-v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \
-e ENABLE_SPAMASSASSIN=1 \
-e SPAMASSASSIN_SPAM_TO_INBOX=1 \
-e MOVE_SPAM_TO_JUNK=0 \
-e SA_SPAM_SUBJECT="SPAM: " \
-h mail.my-domain.com -t "${NAME}"
wait_for_smtp_port_in_container mail_spam_moved_junk
wait_for_finished_setup_in_container mail_spam_moved_new
}
function teardown_file() {
docker rm -f mail_spam_moved_new
docker rm -f mail_spam_moved_junk
}
@test "first" {
skip 'this test must come first to reliably identify when to run setup_file'
}
@test "checking amavis: spam message is delivered and moved to the Junk folder (MOVE_SPAM_TO_JUNK=1)" {
# send a spam message
run docker exec mail_spam_moved_junk /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt"
assert_success
@ -63,6 +33,21 @@ function teardown_file() {
}
@test "checking amavis: spam message is delivered to INBOX (MOVE_SPAM_TO_JUNK=0)" {
local PRIVATE_CONFIG
PRIVATE_CONFIG="$(duplicate_config_for_container . mail_spam_moved_new)"
docker run -d --name mail_spam_moved_new \
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
-v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \
-e ENABLE_SPAMASSASSIN=1 \
-e SPAMASSASSIN_SPAM_TO_INBOX=1 \
-e MOVE_SPAM_TO_JUNK=0 \
-e SA_SPAM_SUBJECT="SPAM: " \
-h mail.my-domain.com -t "${NAME}"
teardown() { docker rm -f mail_spam_moved_new; }
wait_for_smtp_port_in_container mail_spam_moved_new
# send a spam message
run docker exec mail_spam_moved_new /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt"
assert_success
@ -74,7 +59,3 @@ function teardown_file() {
run repeat_until_success_or_timeout 20 sh -c "docker exec mail_spam_moved_new sh -c 'grep \"Subject: SPAM: \" /var/mail/localhost.localdomain/user1/new/ -R'"
assert_success
}
@test "last" {
skip 'this test is only there to reliably mark the end for the teardown_file'
}

View file

@ -53,6 +53,7 @@ function teardown_file() {
}
@test "checking ssl: manual cert works correctly" {
wait_for_tcp_port_in_container 587 mail_manual_ssl
run docker exec mail_manual_ssl /bin/sh -c "timeout 1 openssl s_client -connect 0.0.0.0:587 -starttls smtp -CApath /etc/ssl/certs/ | grep 'Verify return code: 10 (certificate has expired)'"
assert_success
}