refactor(tests): replace duplicated wait-for helpers with testutil.Wa… - #1039
refactor(tests): replace duplicated wait-for helpers with testutil.Wa…#1039Fayupable wants to merge 1 commit into
Conversation
Greptile SummaryThis PR consolidates duplicated polling helpers into a shared
Confidence Score: 5/5The PR appears safe to merge, with the shared helper preserving the relevant behavior of the removed test-local implementations. The migrated predicates retain their original locking and state checks, while the shared helper provides an equal or longer timeout at every call site.
|
| Filename | Overview |
|---|---|
| internal/testutil/waitfor.go | Introduces the shared polling helper with equivalent behavior and a more generous timeout. |
| internal/agent/async_diagnostics_test.go | Replaces the local idle-wait helper while preserving mutex-protected state inspection. |
| internal/daemon/pool_test.go | Migrates queue-depth polling to the shared helper without changing conditions. |
| internal/daemon/server_test.go | Migrates status-file polling while retaining the original os.Stat success condition. |
| internal/daemon/session_test.go | Migrates session-state polling to the shared helper. |
| internal/swarm/lifecycle_test.go | Removes the package-local helper and migrates lifecycle synchronization checks. |
| internal/swarm/scheduler_test.go | Migrates scheduler completion, spawn, skip, and retirement polling. |
| internal/swarm/tools_test.go | Migrates asynchronous tool-state checks without changing their predicates. |
Reviews (1): Last reviewed commit: "refactor(tests): replace duplicated wait..." | Re-trigger Greptile
There was a problem hiding this comment.
🟢 Approval recommended
The change is a straightforward, verified test-only refactor that removes duplication without altering production behavior.
Pull request overview
This PR consolidates multiple duplicated “poll-until” test helpers into a single shared helper (internal/testutil.WaitFor) to standardize asynchronous waiting behavior across test suites and make future timeout tuning centralized.
Changes:
- Added
internal/testutil.WaitFor(5s default deadline, 5ms poll interval, descriptive timeout failure). - Migrated existing tests in
internal/swarm,internal/daemon, andinternal/agentto usetestutil.WaitFor. - Removed the now-redundant per-file wait helper implementations.
File summaries
| File | Description |
|---|---|
| internal/testutil/waitfor.go | Introduces shared WaitFor polling helper for tests. |
| internal/swarm/tools_test.go | Replaces local wait calls with testutil.WaitFor. |
| internal/swarm/scheduler_test.go | Migrates scheduler polling waits to testutil.WaitFor. |
| internal/swarm/lifecycle_test.go | Removes local helper; updates all waits to testutil.WaitFor. |
| internal/daemon/session_test.go | Updates session state waits to testutil.WaitFor with descriptive labels. |
| internal/daemon/server_test.go | Replaces file-appearance polling helper with testutil.WaitFor + os.Stat. |
| internal/daemon/pool_test.go | Replaces pool queue-depth waits with testutil.WaitFor. |
| internal/agent/async_diagnostics_test.go | Replaces idle-wait helper with testutil.WaitFor using a mutex-protected condition. |
Review details
- Files reviewed: 8/8 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (8)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. WalkthroughThe change adds a shared ChangesShared asynchronous test polling
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This change centralizes asynchronous test polling while preserving the existing conditions being awaited. It affects test behavior only, with no current merge-blocking risk identified. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Fixes #1023
Summary
Extracts the duplicated poll-until helper functions scattered across
internal/swarmandinternal/daemontest files into a single sharedtestutil.WaitForhelper in a newinternal/testutilpackage. All call sites (34 total, across 7 files, since the helper turned out to be used more widely than the 4 locations originally listed in the issue) were migrated to the shared function.Note: I see #1037 is already open for this issue. I had this ready before noticing it, so I'm submitting it as an alternative in case it's useful for comparison.
Linked issue
Fixes #1023
Checklist
issue-approvedlabel.go build ./...,go vet ./..., andgo test ./...pass locally.gofmtclean.-racewhere relevant).Summary by CodeRabbit