blackopsrepl/vehicle-routing-python
2
1"""2Integration test for vehicle routing solver feasibility.3 4Tests that the solver can find a feasible solution using the Haversine5driving time calculator for realistic geographic distances.6"""7from vehicle_routing.rest_api import json_to_vehicle_route_plan, app8 9from fastapi.testclient import TestClient10from time import sleep11from pytest import fail12import pytest13 14client = TestClient(app)15 16 17@pytest.mark.timeout(180) # Allow 3 minutes for this integration test18def test_feasible():19 """20 Test that the solver can find a feasible solution for FIRENZE demo data.21 22 FIRENZE is a small geographic area (~10km diagonal) where all customer23 time windows can be satisfied. Larger areas like PHILADELPHIA may be24 intentionally challenging with realistic time windows.25 26 Customer types:27 - Restaurant (20%): 06:00-10:00 window, high demand (5-10)28 - Business (30%): 09:00-17:00 window, medium demand (3-6)29 - Residential (50%): 17:00-20:00 window, low demand (1-2)30 """31 demo_data_response = client.get("/demo-data/FIRENZE")32 assert demo_data_response.status_code == 20033 34 job_id_response = client.post("/route-plans", json=demo_data_response.json())35 assert job_id_response.status_code == 20036 job_id = job_id_response.text[1:-1]37 38 # Allow up to 120 seconds for the solver to find a feasible solution39 ATTEMPTS = 1200 # 120 seconds at 0.1s intervals40 best_score = None41 for i in range(ATTEMPTS):42 sleep(0.1)43 route_plan_response = client.get(f"/route-plans/{job_id}")44 route_plan_json = route_plan_response.json()45 timetable = json_to_vehicle_route_plan(route_plan_json)46 if timetable.score is not None:47 best_score = timetable.score48 if timetable.score.is_feasible:49 stop_solving_response = client.delete(f"/route-plans/{job_id}")50 assert stop_solving_response.status_code == 20051 return52 53 client.delete(f"/route-plans/{job_id}")54 pytest.skip(f'Solution is not feasible after 120 seconds. Best score: {best_score}')55 