fix: serialize the admin login lookup so concurrent first calls send one request

This commit is contained in:
Latte committed 2026-10-14 16:24:51 +02:00
1 parent e139ae826f
commit c73a7cc3ce
2 files changed
+35 -5

No files matched your search

+27 -2
View File
@@ -17,8 +17,13 @@ from aegis_gitea_mcp.auth import (
StaticBearerVerifier,
)
from aegis_gitea_mcp.errors import ToolError
from aegis_gitea_mcp.gitea import GiteaExecutor
from tests.test_server_helpers import API, BEARER_TOKEN, GITEA_TOKEN, server_settings
from aegis_gitea_mcp.gitea import GiteaExecutor, ToolOutcome
from tests.test_server_helpers import (
API,
BEARER_TOKEN,
GITEA_TOKEN,
server_settings,
)
# Static bearer verifier
@@ -171,3 +176,23 @@ async def test_missing_gitea_token_is_refused() -> None:
with pytest.raises(ToolError, match="GITEA_TOKEN"):
await resolver.resolve(None)
async def test_concurrent_first_calls_send_one_login_lookup() -> None:
import asyncio
lookups: list[str] = []
class SlowExecutor(GiteaExecutor):
async def request(self, method: str, path: str, *args: Any, **kwargs: Any) -> ToolOutcome:
lookups.append(path)
await asyncio.sleep(0.01) # a real network round trip yields to other calls
return ToolOutcome(False, {"data": {"login": "admin"}}, 200)
settings = server_settings()
resolver = AdminIdentityResolver(settings, SlowExecutor(settings))
identities = await asyncio.gather(*(resolver.resolve(None) for _ in range(10)))
assert {identity.login for identity in identities} == {"admin"}
assert lookups == ["/user"]