reworked
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
python "%~dp0restart.py"
|
||||
exit /b %ERRORLEVEL%
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Restart API, PostgreSQL and Redis without removing named volumes."""
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def main() -> int:
|
||||
env_file = ROOT / ".env"
|
||||
cmd = ["docker", "compose"]
|
||||
if env_file.is_file():
|
||||
cmd.extend(["--env-file", str(env_file)])
|
||||
cmd.extend(["restart", "postgres", "redis", "api"])
|
||||
return subprocess.run(cmd, cwd=ROOT).returncode
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
cd "$ROOT"
|
||||
if [ -f .env ]; then
|
||||
docker compose --env-file .env restart postgres redis api
|
||||
else
|
||||
docker compose restart postgres redis api
|
||||
fi
|
||||
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Recreate API with SESSION_TTL_SECONDS=2, test expiry, restore TTL."""
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def compose(args, extra_env=None):
|
||||
env = os.environ.copy()
|
||||
if extra_env:
|
||||
env.update(extra_env)
|
||||
cmd = ["docker", "compose"]
|
||||
if (ROOT / ".env").is_file():
|
||||
cmd.extend(["--env-file", str(ROOT / ".env")])
|
||||
cmd.extend(args)
|
||||
proc = subprocess.run(cmd, cwd=ROOT, env=env)
|
||||
if proc.returncode != 0:
|
||||
raise SystemExit(proc.returncode)
|
||||
|
||||
|
||||
def wait_ready():
|
||||
import urllib.request
|
||||
|
||||
deadline = time.monotonic() + 90
|
||||
while time.monotonic() < deadline:
|
||||
try:
|
||||
urllib.request.urlopen("http://127.0.0.1:8080/health/ready", timeout=2)
|
||||
return
|
||||
except Exception:
|
||||
time.sleep(0.5)
|
||||
raise SystemExit("API did not become ready")
|
||||
|
||||
|
||||
def main():
|
||||
compose(["up", "-d", "--no-deps", "--force-recreate", "api"], {"SESSION_TTL_SECONDS": "2"})
|
||||
wait_ready()
|
||||
env = os.environ.copy()
|
||||
env["SESSION_TTL_SECONDS"] = "2"
|
||||
env["RUN_EXPIRY"] = "1"
|
||||
proc = subprocess.run(
|
||||
[sys.executable, "-m", "pytest", "student_tests/test_expiry.py", "-q"],
|
||||
cwd=ROOT,
|
||||
env=env,
|
||||
)
|
||||
compose(["up", "-d", "--no-deps", "--force-recreate", "api"], {"SESSION_TTL_SECONDS": "3600"})
|
||||
wait_ready()
|
||||
raise SystemExit(proc.returncode)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user