test: run Windows tests without xdist parallelism

This commit is contained in:
Chris Guidry 2025-12-05 12:23:37 -05:00
commit cf101c2a82
2 changed files with 7 additions and 39 deletions

View file

@ -48,7 +48,13 @@ jobs:
run: uv sync --upgrade run: uv sync --upgrade
- name: Run tests (excluding integration and client_process) - name: Run tests (excluding integration and client_process)
run: uv run pytest --inline-snapshot=disable tests -m "not integration and not client_process" --numprocesses auto --maxprocesses 4 --dist worksteal run: |
if [ "$RUNNER_OS" == "Windows" ]; then
# Run without parallelism on Windows to debug xdist crashes
uv run pytest --inline-snapshot=disable tests -m "not integration and not client_process"
else
uv run pytest --inline-snapshot=disable tests -m "not integration and not client_process" --numprocesses auto --maxprocesses 4 --dist worksteal
fi
shell: bash shell: bash
- name: Run client process tests separately - name: Run client process tests separately

View file

@ -1,51 +1,13 @@
import asyncio
import socket import socket
from collections.abc import Callable from collections.abc import Callable
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
from unittest.mock import patch
import pytest import pytest
from fastmcp.utilities.tests import temporary_settings from fastmcp.utilities.tests import temporary_settings
# Fakeredis doesn't properly implement blocking xread - it returns immediately
# instead of waiting. This causes Docket._monitor_strikes to busy-loop, which
# overwhelms pytest-xdist workers on Windows. Replace with a simple sleep loop.
# See: https://github.com/cunla/fakeredis-py/issues/274
async def _mock_monitor_strikes(self):
while True:
await asyncio.sleep(60)
_monitor_strikes_patch = patch(
"docket.docket.Docket._monitor_strikes", _mock_monitor_strikes
)
_monitor_strikes_patch.start()
@pytest.fixture(autouse=True)
def fresh_fakeredis_server():
"""Give each test a fresh FakeServer instead of sharing one.
Docket stores a shared FakeServer as a class attribute (_memory_server).
This can cause issues when many tests run in parallel on Windows.
Reset it before each test to ensure isolation.
"""
from docket import Docket
# Clear the shared server so each test gets a fresh one
if hasattr(Docket, "_memory_server"):
delattr(Docket, "_memory_server")
yield
# Clean up after test
if hasattr(Docket, "_memory_server"):
delattr(Docket, "_memory_server")
def pytest_collection_modifyitems(items): def pytest_collection_modifyitems(items):
"""Automatically mark tests in integration_tests folder with 'integration' marker.""" """Automatically mark tests in integration_tests folder with 'integration' marker."""
for item in items: for item in items: