fix: add pytest to build.sh, fix hanging tests, add request timeouts

This commit is contained in:
2026-07-17 09:18:08 +03:00
parent b445449542
commit e1aa542917
4 changed files with 60 additions and 31 deletions
+24 -16
View File
@@ -1,16 +1,15 @@
"""Smoke tests for pipeline-runner REST API endpoints."""
import json
import os
import shutil
import socket
import subprocess
import tempfile
import time
import pytest
import requests
REQUEST_TIMEOUT = 5
test_get_endpoints = [
("api/pipelines", 200, list),
@@ -21,7 +20,9 @@ test_get_endpoints = [
@pytest.mark.parametrize("endpoint,expected_status,expected_type", test_get_endpoints)
def test_get_endpoints(pipeline_server, endpoint, expected_status, expected_type):
"""Check HTTP status code and response content-type for GET endpoints."""
response = requests.get(f"{pipeline_server.base_url}/{endpoint}")
response = requests.get(
f"{pipeline_server.base_url}/{endpoint}", timeout=REQUEST_TIMEOUT
)
assert response.status_code == expected_status
assert "application/json" in response.headers.get("Content-Type", "")
data = response.json()
@@ -30,7 +31,9 @@ def test_get_endpoints(pipeline_server, endpoint, expected_status, expected_type
def test_cors_headers(pipeline_server):
"""Check that CORS headers are present on responses."""
response = requests.get(f"{pipeline_server.base_url}/api/pipelines")
response = requests.get(
f"{pipeline_server.base_url}/api/pipelines", timeout=REQUEST_TIMEOUT
)
assert response.headers.get("Access-Control-Allow-Origin") == "*"
@@ -45,10 +48,6 @@ def _get_free_port():
@pytest.fixture(scope="module")
def static_file_server():
"""Fixture that starts a server with web_root configured for static file tests."""
project_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
build_script = os.path.join(project_dir, "build.sh")
subprocess.check_call([build_script, "--fake"], cwd=project_dir)
work_dir = tempfile.mkdtemp(prefix="pipeline-static-test-")
web_root = os.path.join(work_dir, "web")
@@ -88,7 +87,7 @@ def static_file_server():
class TestStaticFiles:
def test_serve_html(self, static_file_server):
server, _ = static_file_server
resp = requests.get(f"{server.base_url}/index.html")
resp = requests.get(f"{server.base_url}/index.html", timeout=REQUEST_TIMEOUT)
assert resp.status_code == 200
assert "text/html" in resp.headers.get("Content-Type", "")
assert "<h1>Hello Static</h1>" in resp.text
@@ -96,28 +95,32 @@ class TestStaticFiles:
def test_serve_css(self, static_file_server):
server, _ = static_file_server
resp = requests.get(f"{server.base_url}/style.css")
resp = requests.get(f"{server.base_url}/style.css", timeout=REQUEST_TIMEOUT)
assert resp.status_code == 200
assert "text/css" in resp.headers.get("Content-Type", "")
assert resp.text == "body { color: red; }"
def test_serve_js(self, static_file_server):
server, _ = static_file_server
resp = requests.get(f"{server.base_url}/app.js")
resp = requests.get(f"{server.base_url}/app.js", timeout=REQUEST_TIMEOUT)
assert resp.status_code == 200
assert "text/javascript" in resp.headers.get("Content-Type", "")
assert resp.text == "console.log('hello');"
def test_serve_nested_file(self, static_file_server):
server, _ = static_file_server
resp = requests.get(f"{server.base_url}/subdir/nested.txt")
resp = requests.get(
f"{server.base_url}/subdir/nested.txt", timeout=REQUEST_TIMEOUT
)
assert resp.status_code == 200
assert "text/plain" in resp.headers.get("Content-Type", "")
assert resp.text == "nested file content"
def test_etag_304(self, static_file_server):
server, _ = static_file_server
resp1 = requests.get(f"{server.base_url}/index.html")
resp1 = requests.get(
f"{server.base_url}/index.html", timeout=REQUEST_TIMEOUT
)
assert resp1.status_code == 200
etag = resp1.headers.get("ETag")
assert etag is not None
@@ -125,17 +128,22 @@ class TestStaticFiles:
resp2 = requests.get(
f"{server.base_url}/index.html",
headers={"If-None-Match": etag},
timeout=REQUEST_TIMEOUT,
)
assert resp2.status_code == 304
assert resp2.text == ""
def test_cache_control_header(self, static_file_server):
server, _ = static_file_server
resp = requests.get(f"{server.base_url}/index.html")
resp = requests.get(
f"{server.base_url}/index.html", timeout=REQUEST_TIMEOUT
)
assert resp.status_code == 200
assert "max-age" in resp.headers.get("Cache-Control", "")
def test_static_404(self, static_file_server):
server, _ = static_file_server
resp = requests.get(f"{server.base_url}/nonexistent.html")
resp = requests.get(
f"{server.base_url}/nonexistent.html", timeout=REQUEST_TIMEOUT
)
assert resp.status_code == 404