forked from mtusi2026/mtusi2026lab6
completed lab6
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
# Restore both replicas before and after the unchanged public failure test.
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
restore() {
|
||||
docker compose start api1 api2
|
||||
}
|
||||
trap restore EXIT
|
||||
trap 'exit 130' INT
|
||||
trap 'exit 143' TERM
|
||||
restore
|
||||
"${PYTHON:-python3}" - <<'PY'
|
||||
import os
|
||||
import time
|
||||
import urllib.request
|
||||
base = os.environ.get('BASE_URL', 'http://localhost:8080').rstrip('/')
|
||||
seen = set()
|
||||
deadline = time.monotonic() + 90
|
||||
while time.monotonic() < deadline:
|
||||
try:
|
||||
with urllib.request.urlopen(base + '/health/ready', timeout=3) as response:
|
||||
instance = response.headers.get('X-Instance-Id')
|
||||
if response.status == 200 and instance:
|
||||
seen.add(instance)
|
||||
if {'api1', 'api2'} <= seen:
|
||||
print('Both API replicas are ready through the load balancer')
|
||||
break
|
||||
except OSError:
|
||||
pass
|
||||
time.sleep(0.3)
|
||||
else:
|
||||
raise SystemExit('Both API replicas did not become ready within 90 seconds')
|
||||
PY
|
||||
make test-failover ACTION_SCRIPT=scripts/stop-one.sh
|
||||
Reference in New Issue
Block a user