Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions tests/loadtest/locustfile_rate_limiter_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def _scan_redis_pattern(pattern: str, timeout: int = 20) -> int:
["docker", "exec", DOCKER_REDIS_CONTAINER, "redis-cli", "--scan", "--pattern", pattern],
capture_output=True,
text=True,
timeout=timeout,
timeout=timeout, check=False,
)
if r.returncode != 0:
return 0
Expand Down Expand Up @@ -322,7 +322,7 @@ def _scan_rl_sample_keys(dimension: str, timeout: int = 15) -> list[str]:
["docker", "exec", DOCKER_REDIS_CONTAINER, "redis-cli", "--scan", "--pattern", pattern],
capture_output=True,
text=True,
timeout=timeout,
timeout=timeout, check=False,
)
if r.returncode == 0:
keys.extend(line.strip() for line in r.stdout.splitlines() if line.strip())
Expand All @@ -344,7 +344,7 @@ def _poll_redis_once() -> dict[str, Any] | None:
["docker", "exec", DOCKER_REDIS_CONTAINER, "redis-cli", "DBSIZE"],
capture_output=True,
text=True,
timeout=5,
timeout=5, check=False,
)
total_keys = int(r_dbsize.stdout.strip()) if r_dbsize.returncode == 0 else 0

Expand All @@ -358,7 +358,7 @@ def _poll_redis_once() -> dict[str, Any] | None:
["docker", "exec", DOCKER_REDIS_CONTAINER, "redis-cli", "INFO", "memory"],
capture_output=True,
text=True,
timeout=5,
timeout=5, check=False,
)
mem_bytes = 0
for line in r_mem.stdout.splitlines():
Expand Down Expand Up @@ -397,7 +397,7 @@ def _detect_algorithm_from_redis() -> str:
["docker", "exec", DOCKER_REDIS_CONTAINER, "redis-cli", "TYPE", sample_keys[0]],
capture_output=True,
text=True,
timeout=5,
timeout=5, check=False,
)
key_type = r_type.stdout.strip().lower()

Expand Down Expand Up @@ -831,10 +831,10 @@ def on_test_stop(environment, **kwargs):
print(f" RL key delta: {delta_rl_keys:,} (baseline-subtracted)")
if delta_rl_keys > 0:
print(f" Mem per RL key: {per_key:.2f} KiB (delta_mem / delta_keys — same sample)")
print(f"\n Expected per-key cost by algorithm:")
print(f" fixed_window: ~0.1–0.3 KiB (single integer + TTL)")
print("\n Expected per-key cost by algorithm:")
print(" fixed_window: ~0.1–0.3 KiB (single integer + TTL)")
print(f" sliding_window: ~1–3 KiB (sorted set, {RL_LIMIT_PER_MIN} float entries)")
print(f" token_bucket: ~0.2 KiB (hash: tokens + last_refill)")
print(" token_bucket: ~0.2 KiB (hash: tokens + last_refill)")
if per_key < 0.5:
verdict = "✅ consistent with fixed_window"
elif per_key <= 5.0:
Expand All @@ -845,7 +845,7 @@ def on_test_stop(environment, **kwargs):

# Latency
if total_http > 0:
print(f"\n Response Times (ms):")
print("\n Response Times (ms):")
print(f" Average: {stats.total.avg_response_time:>8.1f}")
print(f" p50: {stats.total.get_response_time_percentile(0.50):>8.1f}")
print(f" p90: {stats.total.get_response_time_percentile(0.90):>8.1f}")
Expand Down
1 change: 1 addition & 0 deletions tests/unit/mcpgateway/middleware/test_auth_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ async def test_invalid_referer_url_treated_as_api_request():
assert response.status_code == 401
assert "Token has been revoked" in response.body.decode()


@pytest.mark.asyncio
async def test_oauth_callback_referer_allows_browser_continuation():
"""OAuth callback referer should be treated as same-origin and allow browser request to continue."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
"""

# Standard
from unittest.mock import AsyncMock, MagicMock, patch
from unittest.mock import MagicMock, patch

# Third-Party
import pytest
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse, RedirectResponse
from starlette.middleware.base import BaseHTTPMiddleware

# First-Party
from mcpgateway.db import EmailUser
Expand Down
9 changes: 4 additions & 5 deletions tests/unit/mcpgateway/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from sqlalchemy.exc import SQLAlchemyError

# First-Party
import mcpgateway.db as db
from mcpgateway import db


# --- utc_now ---
Expand Down Expand Up @@ -2114,7 +2114,6 @@ def __exit__(self, exc_type, exc, tb):

def test_refresh_slugs_on_startup_outer_sqlalchemy_error(monkeypatch, caplog):
# Third-Party
from sqlalchemy.exc import SQLAlchemyError

class DummySession:
def __enter__(self):
Expand Down Expand Up @@ -2985,7 +2984,7 @@ def test_email_api_token_is_expired_none():


def test_db_tool_title_property(test_db):
import mcpgateway.db as db
from mcpgateway import db

tool = db.Tool(
id="tool-1",
Expand All @@ -3007,7 +3006,7 @@ def test_db_tool_title_property(test_db):


def test_db_resource_title_property(test_db):
import mcpgateway.db as db
from mcpgateway import db

resource = db.Resource(
id="resource-1",
Expand All @@ -3026,7 +3025,7 @@ def test_db_resource_title_property(test_db):


def test_db_prompt_title_property(test_db):
import mcpgateway.db as db
from mcpgateway import db

prompt = db.Prompt(
id="prompt-1",
Expand Down
8 changes: 0 additions & 8 deletions tests/unit/mcpgateway/test_observability.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"""

# Standard
import importlib
import inspect
import os
from unittest.mock import MagicMock, patch

Expand All @@ -19,18 +17,12 @@
from mcpgateway import observability
from mcpgateway.config import get_settings
from mcpgateway.observability import (
BaggageSpanAttributePolicy,
configure_baggage_span_attribute_policy,
OpenTelemetryRequestMiddleware,
create_span,
extract_baggage_span_attribute_policy,
inject_trace_context_headers,
init_telemetry,
otel_context_active,
otel_tracing_enabled,
trace_operation,
)
from mcpgateway.utils.trace_context import clear_trace_context, set_trace_context_from_teams, set_trace_session_id


class TestObservability:
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/mcpgateway/test_translate_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
"""

# Standard
from types import SimpleNamespace

# Third-Party
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
import pytest
from unittest.mock import AsyncMock, MagicMock

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/mcpgateway/utils/test_check_schema_at_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from unittest.mock import MagicMock, Mock, patch

# First-Party
import mcpgateway.utils.check_schema_at_head as check_schema_at_head
from mcpgateway.utils import check_schema_at_head


def _build_mock_engine_with_connect():
Expand Down
6 changes: 2 additions & 4 deletions tests/unit/plugins/test_unified_pdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
from __future__ import annotations

import pytest
import httpx
from unittest.mock import AsyncMock, patch

# ---------------------------------------------------------------------------
# Adjust imports – works whether you run from repo root or this directory
Expand Down Expand Up @@ -46,8 +44,8 @@
from plugins.unified_pdp.engines.cedar_engine import CedarEngineAdapter
from plugins.unified_pdp.engines.native_engine import NativeRBACAdapter
from plugins.unified_pdp.engines.mac_engine import MACEngineAdapter
from plugins.unified_pdp.cache import DecisionCache, _build_cache_key
from plugins.unified_pdp.adapter import PolicyEvaluationError, PolicyEngineUnavailableError
from plugins.unified_pdp.cache import DecisionCache
from plugins.unified_pdp.adapter import PolicyEvaluationError

# ===========================================================================
# Fixtures
Expand Down
Loading