19 lines
1.0 KiB
Python
19 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Separate API container with 2 second TTL; main API configuration is unchanged."""
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
root = Path(__file__).resolve().parents[1]
|
|
command = ['docker', 'compose', 'run', '-d', '--no-deps', '-e', 'SESSION_TTL_SECONDS=2', 'api']
|
|
identifier = subprocess.check_output(command, cwd=root, text=True).strip()
|
|
try:
|
|
# Start the client in the temporary container after its HTTP server is ready.
|
|
subprocess.run(['docker', 'exec', identifier, 'python', '-c',
|
|
"import time,urllib.request; "
|
|
"\nfor _ in range(50):\n try:\n urllib.request.urlopen('http://localhost:8080/health/ready',timeout=3); break"
|
|
"\n except OSError: time.sleep(.2)\nelse: raise RuntimeError('API not ready')"], check=True)
|
|
subprocess.run(['docker', 'exec', identifier, 'python', 'student-tests/test_expiry.py'], check=True)
|
|
finally:
|
|
subprocess.run(['docker', 'rm', '-f', identifier], check=True, stdout=subprocess.DEVNULL)
|