From 4cc82a2782aa1aaaca360baec889a0620db190e1 Mon Sep 17 00:00:00 2001 From: Bill Date: Sun, 30 Nov 2025 17:52:00 -0500 Subject: [PATCH] feat: add integration test --- requirements.txt | 1 + tests/test_integration.py | 76 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 tests/test_integration.py diff --git a/requirements.txt b/requirements.txt index 00c394f..9e12b46 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ pydantic==2.12.5 pytest==8.3.0 pytest-asyncio==0.24.0 httpx==0.28.1 +requests==2.32.0 diff --git a/tests/test_integration.py b/tests/test_integration.py new file mode 100644 index 0000000..ac41f1c --- /dev/null +++ b/tests/test_integration.py @@ -0,0 +1,76 @@ +""" +Integration test - requires Docker and FFmpeg. +Run with: pytest tests/test_integration.py -v -s +""" +import pytest +import subprocess +import time +import requests +import os + +WORKER_URL = "http://localhost:8000" + + +@pytest.fixture(scope="module") +def docker_compose(): + """Start docker-compose for integration tests.""" + # Skip if not running integration tests + if os.environ.get("SKIP_INTEGRATION"): + pytest.skip("Skipping integration tests") + + # Create a test video file + data_dir = os.path.join(os.path.dirname(__file__), "..", "data") + os.makedirs(data_dir, exist_ok=True) + test_input = os.path.join(data_dir, "test_input.mp4") + + # Generate test video with FFmpeg (2 seconds of color bars) + subprocess.run([ + "ffmpeg", "-y", "-f", "lavfi", "-i", "testsrc=duration=2:size=320x240:rate=30", + "-c:v", "libx264", "-pix_fmt", "yuv420p", test_input + ], check=True, capture_output=True) + + # Start docker-compose + subprocess.run(["docker-compose", "up", "-d", "--build"], check=True) + + # Wait for service to be ready + for _ in range(30): + try: + response = requests.get(f"{WORKER_URL}/health") + if response.status_code == 200: + break + except requests.ConnectionError: + pass + time.sleep(1) + else: + pytest.fail("Service did not start in time") + + yield + + # Cleanup + subprocess.run(["docker-compose", "down"], check=True) + + +def test_full_workflow(docker_compose): + """Test complete job submission and processing workflow.""" + # Submit job + response = requests.post( + f"{WORKER_URL}/jobs", + json={"command": "-i test_input.mp4 -c:v libx264 -crf 28 test_output.mp4"} + ) + assert response.status_code == 201 + job = response.json() + job_id = job["id"] + assert job["status"] == "queued" + + # Poll for completion + for _ in range(60): + response = requests.get(f"{WORKER_URL}/jobs/{job_id}") + assert response.status_code == 200 + job = response.json() + + if job["status"] in ("completed", "failed"): + break + time.sleep(1) + + assert job["status"] == "completed", f"Job failed: {job.get('error')}" + assert "test_output.mp4" in job["output_files"]