test: Migrate load test framework to anyio as well

This commit is contained in:
Chris Coutinho
2025-10-18 21:03:24 +02:00
parent 1459fe9bc8
commit 240ceb3808
4 changed files with 8 additions and 27 deletions
+2 -1
View File
@@ -18,6 +18,7 @@ from collections import Counter
from contextlib import asynccontextmanager
from typing import Any
import anyio
import click
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
@@ -494,7 +495,7 @@ def main(
print(f"Results exported to: {output}")
try:
asyncio.run(run())
anyio.run(run)
except KeyboardInterrupt:
print("\nBenchmark interrupted by user")
sys.exit(130)
+2 -2
View File
@@ -11,9 +11,9 @@ Usage:
uv run python -m tests.load.cleanup_loadtest_users --dry-run
"""
import asyncio
import sys
import anyio
import click
from nextcloud_mcp_server.client import NextcloudClient
@@ -110,7 +110,7 @@ def main(prefix: str, dry_run: bool):
# Delete users with custom prefix
uv run python -m tests.load.cleanup_loadtest_users --prefix mytest
"""
asyncio.run(cleanup_users(prefix=prefix, dry_run=dry_run))
anyio.run(cleanup_users, prefix, dry_run)
if __name__ == "__main__":
+2 -1
View File
@@ -23,6 +23,7 @@ from http.server import BaseHTTPRequestHandler, HTTPServer
from typing import Any
from urllib.parse import parse_qs, urlparse
import anyio
import click
import httpx
from playwright.async_api import async_playwright
@@ -729,7 +730,7 @@ def main(
print(f"Results exported to: {output}")
try:
asyncio.run(run())
anyio.run(run)
except KeyboardInterrupt:
print("\nBenchmark interrupted by user")
sys.exit(130)
+2 -23
View File
@@ -180,13 +180,8 @@ class OAuthUserPool:
# Clean up streamable context if session creation failed
try:
await streamable_context.__aexit__(None, None, None)
except RuntimeError as cleanup_error:
if "cancel scope" in str(cleanup_error):
logger.debug(
f"Ignoring cancel scope teardown issue: {cleanup_error}"
)
else:
raise
except Exception as cleanup_error:
logger.debug(f"Error during cleanup: {cleanup_error}")
raise e
async def close_user_session(self, username: str):
@@ -200,13 +195,6 @@ class OAuthUserPool:
if profile.session:
try:
await profile.session.__aexit__(None, None, None)
except RuntimeError as e:
if "cancel scope" in str(e):
logger.debug(
f"Ignoring cancel scope teardown issue for {username}: {e}"
)
else:
logger.debug(f"Error closing session for {username}: {e}")
except Exception as e:
logger.debug(f"Error closing session for {username}: {e}")
profile.session = None
@@ -215,15 +203,6 @@ class OAuthUserPool:
if profile.streamable_context:
try:
await profile.streamable_context.__aexit__(None, None, None)
except RuntimeError as e:
if "cancel scope" in str(e):
logger.debug(
f"Ignoring cancel scope teardown issue for {username}: {e}"
)
else:
logger.debug(
f"Error closing streamable context for {username}: {e}"
)
except Exception as e:
logger.debug(f"Error closing streamable context for {username}: {e}")
profile.streamable_context = None