ci: add automated smoke tests
CI / smoke-test (push) Failing after 2m8s

This commit is contained in:
Mikhail Lobanov
2026-10-14 12:48:39 +03:00
parent 53cbf79e6f
commit 2bff70c0c5
2 changed files with 81 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
smoke-test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Run smoke tests
run: python3 scripts/smoke_test.py
+56
View File
@@ -0,0 +1,56 @@
import json
import subprocess
import sys
import time
import urllib.error
import urllib.request
process = subprocess.Popen(
[sys.executable, "-u", "app/app.py"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
try:
base_url = "http://127.0.0.1:8000"
response = None
for _ in range(30):
if process.poll() is not None:
raise RuntimeError("Приложение завершилось до запуска")
try:
response = urllib.request.urlopen(
f"{base_url}/health", timeout=1
)
break
except (urllib.error.URLError, TimeoutError):
time.sleep(1)
if response is None:
raise RuntimeError("Приложение не ответило за 30 секунд")
with response:
assert response.status == 200
data = json.loads(response.read().decode("utf-8"))
assert data.get("status") == "ok", data
with urllib.request.urlopen(base_url, timeout=3) as response:
assert response.status == 200
try:
urllib.request.urlopen(f"{base_url}/unknown", timeout=3)
except urllib.error.HTTPError as error:
assert error.code == 404, error.code
else:
raise AssertionError("Для /unknown ожидался HTTP 404")
print("Smoke tests passed!")
finally:
process.terminate()
try:
process.wait(timeout=5)
except subprocess.TimeoutExpired:
process.kill()
process.wait()