Test HAProxy start functionality.
(haproxy_api_cleanup)
| 1275 | |
| 1276 | @pytest.mark.asyncio |
| 1277 | async def test_start(haproxy_api_cleanup): |
| 1278 | """Test HAProxy start functionality.""" |
| 1279 | with tempfile.TemporaryDirectory() as temp_dir: |
| 1280 | config_file_path = os.path.join(temp_dir, "haproxy.cfg") |
| 1281 | socket_path = os.path.join(temp_dir, "admin.sock") |
| 1282 | |
| 1283 | # Create HAProxy config |
| 1284 | config = HAProxyConfig( |
| 1285 | http_options=HTTPOptions( |
| 1286 | host="127.0.0.1", |
| 1287 | port=8000, |
| 1288 | keep_alive_timeout_s=58, |
| 1289 | ), |
| 1290 | stats_port=8404, |
| 1291 | pass_health_checks=True, |
| 1292 | socket_path=socket_path, |
| 1293 | has_received_routes=True, |
| 1294 | has_received_servers=True, |
| 1295 | ) |
| 1296 | |
| 1297 | # Add a backend so routes are populated |
| 1298 | backend = BackendConfig( |
| 1299 | name="test_backend", |
| 1300 | path_prefix="/", |
| 1301 | app_name="test_app", |
| 1302 | servers=[ServerConfig(name="server", host="127.0.0.1", port=9999)], |
| 1303 | ) |
| 1304 | |
| 1305 | api = HAProxyApi( |
| 1306 | cfg=config, |
| 1307 | backend_configs={"test_backend": backend}, |
| 1308 | config_file_path=config_file_path, |
| 1309 | ) |
| 1310 | |
| 1311 | haproxy_api_cleanup(api) |
| 1312 | |
| 1313 | await api.start() |
| 1314 | |
| 1315 | assert api._proc is not None, "HAProxy process should exist" |
| 1316 | assert api._is_running(), "HAProxy should be running" |
| 1317 | |
| 1318 | # Verify config file contains expected content |
| 1319 | with open(config_file_path, "r") as f: |
| 1320 | config_content = f.read() |
| 1321 | assert "frontend http_frontend" in config_content |
| 1322 | assert f"bind 127.0.0.1:{config.frontend_port}" in config_content |
| 1323 | assert "acl healthcheck path -i /-/healthz" in config_content |
| 1324 | |
| 1325 | health_response = requests.get( |
| 1326 | f"http://127.0.0.1:{config.frontend_port}/-/healthz", timeout=5 |
| 1327 | ) |
| 1328 | assert ( |
| 1329 | health_response.status_code == 503 |
| 1330 | ), "Health check with no servers up should return 503" |
| 1331 | |
| 1332 | await api.stop() |
| 1333 | assert api._proc is None |
| 1334 | assert not api._is_running() |
nothing calls this directly
no test coverage detected
searching dependent graphs…