"""Wait until both real API aliases are observed through the LB.""" import os import time import urllib.request base = os.environ.get('BASE_URL', 'http://localhost:8080') seen = set() deadline = time.monotonic() + 20 while time.monotonic() < deadline: try: with urllib.request.urlopen(base + '/health/ready', timeout=2) as reply: seen.add(reply.headers['X-Instance-Id']) except OSError: pass if {'api1', 'api2'} <= seen: print('PASS: both replicas observed through LB') break time.sleep(0.15) else: raise SystemExit('Both API replicas did not return to LB')