Skip to content

test: cover per-phase drain timeout in BenchmarkSession#402

Open
wu6u3tw wants to merge 1 commit into
mlcommons:mainfrom
wu6u3tw:wan22-drain-timeouts
Open

test: cover per-phase drain timeout in BenchmarkSession#402
wu6u3tw wants to merge 1 commit into
mlcommons:mainfrom
wu6u3tw:wan22-drain-timeouts

Conversation

@wu6u3tw

@wu6u3tw wu6u3tw commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

The original version of this PR made per-phase in-flight drain timeouts configurable. That feature has since landed on main via #330 and #337 (settings.drain / DrainConfig, PhaseConfig.drain_timeout, unbounded accuracy drain), so this PR is reduced to the one piece main still lacks: a session-level regression test.

  • test_drain_respects_per_phase_timeout: a phase whose in-flight samples never complete must exit the drain wait after drain_timeout seconds instead of hanging.

Test plan

  • uv run pytest tests/unit/load_generator/test_async_session.py -k drain (3 passed)
  • pre-commit run on the changed file (ruff, mypy, license header all pass)

@wu6u3tw wu6u3tw requested a review from a team July 8, 2026 21:49
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces configurable per-phase in-flight drain timeouts via a new DrainConfig schema, replacing the hard-coded 240-second timeout to better support slow generative workloads. The reviewer identified a potential TypeError and rounding issue in _drain_inflight where formatting timeout_s (which can be None or a sub-second float) with %.0f in the error log could fail or display misleadingly as 0 s. Suggestions were provided to safely format the timeout string and update the corresponding unit test assertion.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines 461 to 475
logger.info(
"Draining %d in-flight responses (timeout: %s)...",
phase_issuer.inflight,
f"{timeout_s:.0f} s" if timeout_s is not None else "none",
)
self._drain_event.clear()
try:
await asyncio.wait_for(self._drain_event.wait(), timeout=240.0)
await asyncio.wait_for(self._drain_event.wait(), timeout=timeout_s)
except TimeoutError:
logger.error(
"Drain timed out after 240 s with %d responses still in flight; "
"Drain timed out after %.0f s with %d responses still in flight; "
"proceeding to next phase.",
timeout_s,
phase_issuer.inflight,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The timeout_s parameter is typed as float | None. Formatting it directly with %.0f in logger.error can trigger a TypeError at runtime if TimeoutError is raised while timeout_s is None (or cause static type checkers like mypy to fail). Additionally, using :.0f or %.0f rounds sub-second timeouts (like 0.1 s in tests) to 0 s, which is misleading.

We can define a helper string timeout_str to format the timeout safely and precisely for both log messages.

Suggested change
logger.info(
"Draining %d in-flight responses (timeout: %s)...",
phase_issuer.inflight,
f"{timeout_s:.0f} s" if timeout_s is not None else "none",
)
self._drain_event.clear()
try:
await asyncio.wait_for(self._drain_event.wait(), timeout=240.0)
await asyncio.wait_for(self._drain_event.wait(), timeout=timeout_s)
except TimeoutError:
logger.error(
"Drain timed out after 240 s with %d responses still in flight; "
"Drain timed out after %.0f s with %d responses still in flight; "
"proceeding to next phase.",
timeout_s,
phase_issuer.inflight,
)
timeout_str = f"{timeout_s} s" if timeout_s is not None else "none"
logger.info(
"Draining %d in-flight responses (timeout: %s)...",
phase_issuer.inflight,
timeout_str,
)
self._drain_event.clear()
try:
await asyncio.wait_for(self._drain_event.wait(), timeout=timeout_s)
except TimeoutError:
logger.error(
"Drain timed out after %s with %d responses still in flight; "
"proceeding to next phase.",
timeout_str,
phase_issuer.inflight,
)


result = await asyncio.wait_for(session.run(phases), timeout=10.0)
assert result is not None
assert "Drain timed out after 0 s" in caplog.text or "Drain timed out" in caplog.text

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since we updated the log formatting to preserve decimal values for sub-second timeouts (avoiding rounding 0.1 s to 0 s), we can simplify and make this assertion more precise.

Suggested change
assert "Drain timed out after 0 s" in caplog.text or "Drain timed out" in caplog.text
assert "Drain timed out after 0.1 s" in caplog.text

@wu6u3tw wu6u3tw force-pushed the wan22-drain-timeouts branch from c143e68 to 36b43f1 Compare July 8, 2026 22:15
@wu6u3tw

wu6u3tw commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

Applied both review suggestions: drain log lines now format the timeout via a shared timeout_str (no %.0f on a possibly-None float, and sub-second values like 0.1 s print exactly), and the test asserts the precise "Drain timed out after 0.1 s" message. Also trimmed the inline comments/docstrings. 101 session+config tests pass.

Comment thread src/inference_endpoint/config/schema.py Outdated
help="Warmup drain timeout in seconds (None = wait indefinitely)",
),
] = Field(
warmup_timeout_s: float | None = Field(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would in general avoid adding more fine-granularity flag to control timeout at each phase, because it adds burden to the whole system and makes config even more difficult to understand/write.

@arekay-nv @viraatc do you think we should just set an arbitrary large timeout and fail out if the timeout is hit? The silent timeout has caused us lots of trouble in tuning because it will pretend successful run while some samples are actually dropped.

The per-phase drain timeout feature (settings.drain, PhaseConfig.drain_timeout)
landed via mlcommons#330 and mlcommons#337 but had no session-level regression test. Add one:
a phase whose samples never complete must exit the drain wait after
drain_timeout seconds instead of hanging.
@wu6u3tw wu6u3tw force-pushed the wan22-drain-timeouts branch from 36b43f1 to a31fe03 Compare July 9, 2026 19:20
@wu6u3tw wu6u3tw changed the title Make per-phase in-flight drain timeouts configurable (settings.drain) test: cover per-phase drain timeout in BenchmarkSession Jul 9, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@55e518a). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #402   +/-   ##
=======================================
  Coverage        ?   80.09%           
=======================================
  Files           ?      129           
  Lines           ?    17276           
  Branches        ?        0           
=======================================
  Hits            ?    13838           
  Misses          ?     3438           
  Partials        ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

3 participants