mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-07-02 23:05:46 +00:00
Update to docker-gen 0.7.0
Since [1] some timings seem to have changed. This caused the unit tests
to fail intermittently, from my testings especially on Ubuntu systems
(much less often on e.g. Arch).
This commit adds the `dockergen_wait_for_event` helper-function to try
and wait for the configuration to be generated by docker-gen before
continuing on with the actual tests themselves.
Additionally, at the end of every test file, all containers spun up by
the bats-tests will be stopped. This required adding the `bats-type`
label to every container started during the bats-tests.
The stopping of the containers reduces the amount of events docker-gen
has to process, thus resulting in lower wait times for the generation to
happen.
[1]: 50435652b1
This commit is contained in:
@ -33,6 +33,7 @@ function nginxproxy {
|
||||
shift
|
||||
docker_clean $container_name \
|
||||
&& docker run -d \
|
||||
--label bats-type="nginx-proxy" \
|
||||
--name $container_name \
|
||||
"$@" \
|
||||
$SUT_IMAGE \
|
||||
@ -66,7 +67,7 @@ function curl_container {
|
||||
local -r container=$1
|
||||
local -r path=$2
|
||||
shift 2
|
||||
docker run appropriate/curl --silent \
|
||||
docker run --label bats-type="curl" appropriate/curl --silent \
|
||||
--connect-timeout 5 \
|
||||
--max-time 20 \
|
||||
"$@" \
|
||||
@ -128,7 +129,39 @@ function prepare_web_container {
|
||||
# THEN querying directly port works
|
||||
IFS=$' \t\n' # See https://github.com/sstephenson/bats/issues/89
|
||||
for port in $ports; do
|
||||
run retry 5 1s docker run appropriate/curl --silent --fail http://$(docker_ip $container_name):$port/data
|
||||
run retry 5 1s docker run --label bats-type="curl" appropriate/curl --silent --fail http://$(docker_ip $container_name):$port/data
|
||||
assert_output "answer from port $port"
|
||||
done
|
||||
}
|
||||
|
||||
# stop all containers with the "bats-type" label (matching the optionally supplied value)
|
||||
#
|
||||
# $1 optional label value
|
||||
function stop_bats_containers {
|
||||
local -r value=$1
|
||||
|
||||
if [ -z "$value" ]; then
|
||||
CIDS=( $(docker ps -q --filter "label=bats-type") )
|
||||
else
|
||||
CIDS=( $(docker ps -q --filter "label=bats-type=$value") )
|
||||
fi
|
||||
|
||||
if [ ${#CIDS[@]} -gt 0 ]; then
|
||||
docker stop ${CIDS[@]} >&2
|
||||
fi
|
||||
}
|
||||
|
||||
# wait for a docker-gen container to receive a specified event from a
|
||||
# container with the specified ID/name
|
||||
#
|
||||
# $1 docker-gen container name
|
||||
# $2 event
|
||||
# $3 ID/name of container to receive event from
|
||||
function dockergen_wait_for_event {
|
||||
local -r container=$1
|
||||
local -r event=$2
|
||||
local -r other=$3
|
||||
local -r did=$(docker_id "$other")
|
||||
docker_wait_for_log "$container" 9 "Received event $event for container ${did:0:12}"
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user