refactor: reuse routing and remove unused analysis helpers
Generic Container CI/CD / test-build-publish (push) Successful in 4m3s
Server CI/CD v2 / build-test-publish-and-deploy (push) Successful in 4m3s

This commit is contained in:
2026-11-09 18:49:32 +08:00
parent 6a4478bfe4
commit e47c61c121
6 changed files with 107 additions and 103 deletions
+27
View File
@@ -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"