Skip to content

Commit 5c64d3f

Browse files
committed
Add wait_ready script and update CI workflow to check API readiness
1 parent f92306d commit 5c64d3f

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

.github/workflows/testrun.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ jobs:
3535
- name: Start the stack
3636
run: docker compose -f docker-compose.ci.yml up -d
3737

38-
- name: Wait for services to be healthy
39-
run: docker compose -f docker-compose.ci.yml exec -T netpalm-api-server python -c "print('ready')"
38+
- name: Wait for API server to be ready
39+
run: docker compose -f docker-compose.ci.yml exec -T netpalm-api-server python -m netpalm.wait_ready
4040

4141
- name: Integration tests
4242
run: docker compose -f docker-compose.ci.yml exec -T netpalm-api-server pytest -m "not fulllab" -vv tests/integration

netpalm/wait_ready.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Block until the local gunicorn process is accepting connections on port 9000."""
2+
3+
import socket
4+
import sys
5+
import time
6+
7+
HOST = "127.0.0.1"
8+
PORT = 9000
9+
TIMEOUT = 120
10+
INTERVAL = 2
11+
12+
13+
def main() -> None:
14+
deadline = time.monotonic() + TIMEOUT
15+
while time.monotonic() < deadline:
16+
try:
17+
with socket.create_connection((HOST, PORT), timeout=2):
18+
print(f"netpalm API ready on {HOST}:{PORT}")
19+
return
20+
except OSError:
21+
time.sleep(INTERVAL)
22+
23+
print(f"netpalm API not ready after {TIMEOUT}s", file=sys.stderr)
24+
sys.exit(1)
25+
26+
27+
if __name__ == "__main__":
28+
main()

0 commit comments

Comments
 (0)