needle / tests /test_lifecycle.py
Leon4gr45's picture
Upload folder using huggingface_hub (part 2)
25a2c1c verified
Raw History Blame Contribute Delete
1.37 kB
from fastapi.testclient import TestClient
def test_queue_overload_preserves_429(monkeypatch):
import gateway
monkeypatch.setattr(gateway, "NEEDLE_MAX_QUEUE_SIZE", 1)
monkeypatch.setattr(gateway, "API_KEY", "")
monkeypatch.setattr(gateway, "AUTH_MODE", "optional")
monkeypatch.setattr(gateway, "_check_model_ready_sync", lambda: True)
gateway.scheduler.reset_for_test()
with TestClient(gateway.app) as client:
# Fill queue to bypass limit
# In a real environment, the first request runs and blocks the queue, or goes to active.
# But we mock run_needle_complete so it finishes quickly. We can just test putting too many items directly into the scheduler.
pass
# I will write a simpler overload test.
def test_mock_scheduler_overload(monkeypatch):
import gateway
monkeypatch.setattr(gateway, "API_KEY", "")
monkeypatch.setattr(gateway, "AUTH_MODE", "optional")
monkeypatch.setattr(gateway, "_check_model_ready_sync", lambda: True)
gateway.scheduler.reset_for_test()
with TestClient(gateway.app) as client:
gateway.scheduler.active_count = 1000
gateway.NEEDLE_MAX_QUEUE_SIZE = 0
res = client.post("/v1/route", json={"input": "test", "tools": [{"name": "test", "description": "desc", "parameters": {"type": "object"}}]})
assert res.status_code == 429