Skip to content

Fix: drain scheduler mocks during fixture teardown - #1611

Merged
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
puddingfjz:fix/scheduler-test-teardown-drain
Aug 2, 2026
Merged

Fix: drain scheduler mocks during fixture teardown#1611
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
puddingfjz:fix/scheduler-test-teardown-drain

Conversation

@puddingfjz

@puddingfjz puddingfjz commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a teardown-only drain mode to MockMailboxWorker
  • auto-complete both current and subsequently dispatched work while fixtures unwind
  • cover teardown with overlapping queued groups and singles left intentionally incomplete

Why

An assertion can skip the manual complete() calls in a scheduler test. The existing fixture then calls Scheduler::stop(), which waits forever for mock workers that can no longer be completed. A persistent drain mode handles an arbitrary amount of queued teardown work without a fixed retry count.

Review context

#1565 (comment)

Testing

  • reproduced the pre-fix hang with a 5-second timeout
  • test_scheduler: 27/27 passed
  • non-hardware C++ UT: 67/67 passed

@puddingfjz
puddingfjz force-pushed the fix/scheduler-test-teardown-drain branch from 60ea68a to 11bbeb2 Compare July 31, 2026 15:57
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The test mock worker now supports persistent drain mode. Scheduler fixtures activate this mode before shutdown. A group-scheduler test verifies that teardown completes active and queued dispatches.

Changes

Scheduler teardown draining

Layer / File(s) Summary
Persistent worker drain mode
tests/ut/cpp/hierarchical/test_scheduler.cpp
MockMailboxWorker stores persistent drain state, wakes parked dispatches, and releases dispatches while drain mode is active.
Fixture teardown integration
tests/ut/cpp/hierarchical/test_scheduler.cpp
Scheduler fixtures drain their mock workers before shutdown. A group-scheduler test leaves active and queued work for teardown to complete.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A rabbit found dispatches waiting in line,
“Drain mode,” it said, “will make all things fine.”
Workers woke up and queues became clear,
Then schedulers stopped without fear.
Thump-thump, teardown was done!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the scheduler mock teardown drain change.
Description check ✅ Passed The description explains the teardown drain mode, the failure it fixes, the test coverage, and the observed results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ChaoWao
ChaoWao force-pushed the fix/scheduler-test-teardown-drain branch from 11bbeb2 to 7a52171 Compare August 2, 2026 11:08
@ChaoWao

ChaoWao commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Addressed the two review Considers (review of #1611 — the inline thread and CI were already clean):

  1. drain() semantics — added a comment on the method stating the present-tense contract: it is a persistent teardown mode, so every dispatch including one arriving after the call completes itself, which is what lets Scheduler::stop() always join.

  2. TearDownDrainsCurrentAndQueuedDispatches — added a comment stating what the test actually verifies: work is left deliberately in both states (running, and queued-but-not-yet-dispatched), so teardown drains a worker mid-task and one whose dispatch has not happened yet.

Both are comment-only; behavior unchanged. Rebased onto current main; full scheduler suite green locally (39 tests × 30 iterations).

Failed assertions can leave mock workers running while Scheduler::stop() waits for every worker to become idle. Put the mocks into a teardown-only auto-complete mode so both current and subsequently dispatched work drains before the scheduler joins.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/ut/cpp/hierarchical/test_scheduler.cpp`:
- Around line 931-933: Update the test teardown around the existing
worker_a/worker_b/worker_c drain calls to also drain the registered SUB workers,
including sub_worker_a and sub_worker_b, before invoking sched.stop(). Preserve
the current drain ordering for the next-level workers while ensuring all SUB
dispatch has completed before scheduler shutdown.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9ccca593-5c67-41df-b5fd-a18f3f478c1b

📥 Commits

Reviewing files that changed from the base of the PR and between b69f453 and 7a52171.

📒 Files selected for processing (1)
  • tests/ut/cpp/hierarchical/test_scheduler.cpp

Comment thread tests/ut/cpp/hierarchical/test_scheduler.cpp
@ChaoWao
ChaoWao merged commit 0d86905 into hw-native-sys:main Aug 2, 2026
15 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.

2 participants