Skip to content

test: make test_sleep_manager.py runnable under pytest via pytest-asyncio - #432

Merged
RixinLiu merged 1 commit into
ovg-project:mainfrom
rishabhsinha17:test/pytest-asyncio-sleep-manager
Aug 13, 2026
Merged

RixinLiu merged 1 commit into
ovg-project:mainfrom
rishabhsinha17:test/pytest-asyncio-sleep-manager

Conversation

@rishabhsinha17

Copy link
Copy Markdown
Collaborator

Summary

Make tests/test_sleep_manager.py actually runnable under pytest: 9 passed where every environment previously got 1 failed, 8 errors.

Fixes #431.

Problem

The file is written as a sequential live-server script (main() shares one SleepManager across steps), but pytest also collects its async def test_* functions. Without an async plugin the first test fails with "async def functions are not natively supported", and the step functions' manager parameter is resolved as a nonexistent fixture, erroring the other eight. As a result controller/sleep_manager.py has zero automated coverage, and async behavior has to be tested through workarounds — #409 wraps asyncio.gather in asyncio.run() inside a sync test for exactly this reason.

Changes

  • add pytest-asyncio to requirements.txt and configure asyncio_mode = "auto" in pyproject.toml, so plain async def tests and fixtures run without per-test markers (and future PRs like fix(controller): don't fail the losing racer of a concurrent wakeup_model() call #409 can write native async tests)
  • add a manager fixture providing a fresh SleepManager per test; main() keeps its own shared manager, so the live-server script mode is unchanged
  • make each step self-contained: the sleep/wake and detection tests register their own models from example-config.yaml instead of relying on state left behind by earlier steps (SleepManager's HTTP helpers already catch connection failures and return False, so these degrade gracefully and quickly when no live endpoint is reachable; the fresh-manager path previously crashed with TypeError: argument of type 'NoneType' is not iterable in the SGLang detection step)
  • convert deterministic print-only checks into assertions (config defaults, model registry add/remove, config updates, API-method presence). This surfaced that two of the printed "checks" referenced methods that do not exist — _call_vllm_wake_api and handle_model_wakeup printed False and could never fail; the assertions now cover the real _call_vllm_wakeup_api and handle_model_wakeup_on_request

Validation

python -m pytest tests/test_sleep_manager.py -q   # 9 passed in 1.86s   (before: 1 failed, 8 errors)
python tests/test_sleep_manager.py                # script mode intact, exit 0

The full CPU-only suite passes with asyncio_mode = "auto" enabled (82 passed, 1 skipped — the 73 previously-passing tests plus these 9). No live vLLM/SGLang endpoints are required; with servers configured, the script path exercises the real sleep/wake cycle exactly as before. ruff check, isort --check-only, and mypy pass on the changed files.

Once this and #428 (or #403) land, the CPU CI job can stop excluding this file.

…ncio

pytest collected the async def tests but failed them all (no async plugin)
and resolved the script-style manager parameter as a nonexistent fixture,
so controller/sleep_manager.py had zero automated coverage and async
behavior could only be tested through asyncio.run() workarounds.

Add pytest-asyncio with asyncio_mode=auto, provide a manager fixture,
make each step self-contained (tests register their own models and
degrade gracefully with no live server), and convert deterministic
prints into assertions. The live-server script mode is unchanged.

Since the file no longer needs live vLLM/SGLang endpoints, move it from
the integration manifest to the cpu manifest added in ovg-project#403, which adds
9 tests to the CPU CI run. tools/check_test_classification.py reports
total=26, cpu=16, gpu=5, integration=5.

Fixes ovg-project#431
@rishabhsinha17

Copy link
Copy Markdown
Collaborator Author

Rebased onto main and folded in the manifest side of this, now that #403 has landed.

tests/test_sleep_manager.py sat in integration.txt because its async tests required live vLLM/SGLang endpoints. With the changes here they are self-contained (each test registers its own models, and the HTTP helpers already return False on connection failure), so the file moves integration -> cpu and its 9 tests join the CPU run.

  • tools/check_test_classification.py: total=26, cpu=16, gpu=5, integration=5
  • pytest tests/test_sleep_manager.py: 9 passed
  • full cpu manifest locally: 119 passed, with only test_shm_info_tracker.py erroring because /dev/shm does not exist on macOS

Closed #428 in favor of #403; this is the part that did not overlap.

@RixinLiu

Copy link
Copy Markdown
Collaborator

LGTM

@RixinLiu
RixinLiu merged commit 094481f into ovg-project:main Aug 13, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests/test_sleep_manager.py async tests can never run under pytest — no pytest-asyncio configuration

2 participants