diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh index 78f0348..79797c0 100755 --- a/scripts/run-tests.sh +++ b/scripts/run-tests.sh @@ -2,6 +2,9 @@ set -e +OPENFAAS_CONTAINER_MAX_ATTEMPS=5 +OPENFAAS_CONTAINER_ATTEMPS=0 + OPENFAAS_CONTAINER="openfaas" QUERY_ENGINE_SERVICE="query-engine" @@ -19,8 +22,25 @@ if ! docker ps --format '{{.Names}}' | grep -q "$OPENFAAS_CONTAINER"; then unset REMOTE fi -while ! docker exec $OPENFAAS_CONTAINER pgrep -f $QUERY_ENGINE_SERVICE >/dev/null; do +while ! docker exec "$OPENFAAS_CONTAINER" pgrep -f "$QUERY_ENGINE_SERVICE" >/dev/null; do + OPENFAAS_EXIT_CODE=$(docker inspect --format='{{.State.ExitCode}}' "$OPENFAAS_CONTAINER") + + if [ "$OPENFAAS_CONTAINER_ATTEMPS" -gt "$OPENFAAS_CONTAINER_MAX_ATTEMPS" ]; then + echo "Exceeded maximum attempts to start the container $OPENFAAS_CONTAINER" + docker logs "$OPENFAAS_CONTAINER" + exit 1 + fi + + if [ "$OPENFAAS_EXIT_CODE" -gt 0 ]; then + echo "The container $OPENFAAS_CONTAINER exited with status code $OPENFAAS_EXIT_CODE" + docker logs "$OPENFAAS_CONTAINER" + exit 1 + fi + echo "Waiting for $QUERY_ENGINE_SERVICE in container $OPENFAAS_CONTAINER to start..." + + OPENFAAS_CONTAINER_ATTEMPS=$(($OPENFAAS_CONTAINER_ATTEMPS + 1)) + sleep 10 done