/ app.py
app.py
1 from fastapi import FastAPI, Query 2 from fastapi.responses import JSONResponse 3 import random 4 import asyncio 5 6 app = FastAPI() 7 8 @app.get("/mock-endpoint") 9 async def mock_endpoint( 10 min_time: int = Query(..., description="Minimum sleep time in ms"), 11 max_time: int = Query(..., description="Maximum sleep time in ms"), 12 failchance: int = Query(..., ge=0, le=100, description="Chance of failure (0-100)") 13 ): 14 if min_time > max_time: 15 return JSONResponse(status_code=400, content={"error": "min_time must be <= max_time"}) 16 sleep_ms = random.randint(min_time, max_time) 17 await asyncio.sleep(sleep_ms / 1000) 18 if random.randint(1, 100) <= failchance: 19 return JSONResponse(status_code=504, content={"error": "Simulated failure"}) 20 return {"status": "ok", "slept_ms": sleep_ms}