#!/bin/sh # Run in a disposable nginx container; never against a running load balancer. set -eu sed '/^check_ready &/,$d' /source/start-nginx.sh > /tmp/readiness-under-test.sh . /tmp/readiness-under-test.sh cycle=0 reloads=0 getent() { printf '192.0.2.1 STREAM api\n'; } wget() { case "$cycle" in 1|2|4|7|8) return 0 ;; *) return 1 ;; esac } nginx() { if [ "$1" = '-s' ]; then reloads=$((reloads + 1)); fi } sleep() { # Check the previous cycle before advancing to the next probe. if [ "$cycle" -gt 0 ]; then case "$cycle" in 2|3|4|5|8) expected=1 ;; *) expected=0 ;; esac actual=0 if grep -q 'server 192.0.2.1:8080 ' "$upstreams"; then actual=1; fi if [ "$actual" -ne "$expected" ]; then printf 'FAIL: cycle %s, expected readiness %s, got %s\n' "$cycle" "$expected" "$actual" >&2 exit 1 fi fi cycle=$((cycle + 1)) if [ "$cycle" -eq 9 ]; then [ "$reloads" -eq 3 ] || exit 1 printf 'PASS: admission, isolated failure, recovery, removal and re-admission; 3 reloads\n' exit 0 fi } check_ready