mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
Implement and use run_until_success_or_timeout
This commit is contained in:
parent
a477040abb
commit
40dd3ae985
|
@ -51,11 +51,7 @@ function teardown_file() {
|
|||
run docker exec mail_with_relays grep -e domainzero.tld /etc/postfix/relayhost_map
|
||||
assert_output ''
|
||||
run ./setup.sh -c mail_with_relays email add user0@domainzero.tld password123
|
||||
for i in {1..10}; do
|
||||
sleep 1
|
||||
run docker exec mail_with_relays grep -e domainzero.tld /etc/postfix/relayhost_map
|
||||
[[ $status == 0 ]] && break
|
||||
done
|
||||
run_until_success_or_timeout 10 docker exec mail_with_relays grep -e domainzero.tld /etc/postfix/relayhost_map
|
||||
assert_output -e '^@domainzero.tld\s+\[default.relay.com\]:2525$'
|
||||
}
|
||||
|
||||
|
@ -63,11 +59,7 @@ function teardown_file() {
|
|||
run docker exec mail_with_relays grep -e domain2.tld /etc/postfix/relayhost_map
|
||||
assert_output ''
|
||||
run ./setup.sh -c mail_with_relays alias add user2@domain2.tld user2@domaintwo.tld
|
||||
for i in {1..10}; do
|
||||
sleep 1
|
||||
run docker exec mail_with_relays grep -e domain2.tld /etc/postfix/relayhost_map
|
||||
[[ $status == 0 ]] && break
|
||||
done
|
||||
run_until_success_or_timeout 10 docker exec mail_with_relays grep -e domain2.tld /etc/postfix/relayhost_map
|
||||
assert_output -e '^@domain2.tld\s+\[default.relay.com\]:2525$'
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,27 @@ function repeat_until_success_or_timeout {
|
|||
done
|
||||
}
|
||||
|
||||
# like repeat_until_success_or_timeout but with wrapping the command to run into `run` for later bats consumption
|
||||
# @param $1 timeout
|
||||
# @param ... test command to run
|
||||
function run_until_success_or_timeout {
|
||||
if ! [[ "$1" =~ ^[0-9]+$ ]]; then
|
||||
echo "First parameter for timeout must be an integer, recieved \"$1\""
|
||||
return 1
|
||||
fi
|
||||
TIMEOUT=$1
|
||||
STARTTIME=$SECONDS
|
||||
shift 1
|
||||
until run "$@" && [[ $status -eq 0 ]]
|
||||
do
|
||||
sleep 1
|
||||
if [[ $(($SECONDS - $STARTTIME )) -gt $TIMEOUT ]]; then
|
||||
echo "Timed out on command: $@" >&2
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# @param $1 timeout
|
||||
# @param $2 container name
|
||||
# @param ... test command for container
|
||||
|
|
Loading…
Reference in a new issue