refactor: reuse routing and remove unused analysis helpers
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
from uuid import uuid4
|
||||
@@ -8,6 +9,32 @@ import pytest
|
||||
from scripts.run_operational_worker import CredentialProvider, OperationalWorker, WorkerSettings
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_parallel_worker_requests_share_cold_and_expired_token_refresh(monkeypatch):
|
||||
clock = [100.0]
|
||||
requests = []
|
||||
monkeypatch.setattr("scripts.run_operational_worker.time.monotonic", lambda: clock[0])
|
||||
|
||||
async def handler(request):
|
||||
requests.append(request)
|
||||
await asyncio.sleep(0)
|
||||
return httpx.Response(200, json={"access_token": f"TEST_ONLY_{len(requests)}", "expires_in": 60})
|
||||
|
||||
provider = CredentialProvider(WorkerSettings(
|
||||
"http://server.test", "http://agent.test", str(uuid4()),
|
||||
token_url="https://identity.test/token", client_id="fixture", client_secret="TEST_ONLY",
|
||||
))
|
||||
async with httpx.AsyncClient(transport=httpx.MockTransport(handler)) as client:
|
||||
first = await asyncio.gather(provider.headers(client), provider.headers(client))
|
||||
assert first[0] == first[1]
|
||||
assert len(requests) == 1
|
||||
clock[0] = 146.0
|
||||
second = await asyncio.gather(provider.headers(client), provider.headers(client))
|
||||
assert second[0] == second[1]
|
||||
assert second[0] != first[0]
|
||||
assert len(requests) == 2
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def anyio_backend():
|
||||
return "asyncio"
|
||||
|
||||
Reference in New Issue
Block a user