Skip to content

refactor: replace context.WithCancel with t.Context - #16509

Merged
yingfeng merged 1 commit into
infiniflow:mainfrom
blackflytech:main
Jul 1, 2026
Merged

yingfeng merged 1 commit into
infiniflow:mainfrom
blackflytech:main

Conversation

@blackflytech

Copy link
Copy Markdown
Contributor

Summary

The addition of the Context method to Go's testing.T provides significant improvements for writing concurrent tests. It allows better management of goroutines, ensuring they properly exit and preventing issues like deadlocks and unfinished processes.

By using Context, errors and cancellations can be handled more effectively, making tests more robust and easier to reason about. This change also enables tighter integration between tests and the application code, especially for systems that span multiple concurrent components. Overall, it simplifies test code and enhances test stability and maintainability.

More info: golang/go#18368

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. ☯️ refactor Pull request that refactor/refine code 🧪 test Pull requests that update test cases. labels Jun 30, 2026
@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a10b5c9d-8197-4519-96ad-a25b6a4b3257

📥 Commits

Reviewing files that changed from the base of the PR and between 45fc7fe and ce15fcc.

📒 Files selected for processing (3)
  • internal/agent/canvas/cancel_test.go
  • internal/harness/core/cancel_full_test.go
  • internal/harness/core/react_graph_test.go

📝 Walkthrough

Walkthrough

Nine test locations across three files replace context.WithCancel(context.Background()) plus defer cancel() with t.Context(), delegating context cancellation to the Go testing framework.

Changes

Test Context Cleanup

Layer / File(s) Summary
Switch all tests to t.Context()
internal/agent/canvas/cancel_test.go, internal/harness/core/cancel_full_test.go, internal/harness/core/react_graph_test.go
Replaces manual context.WithCancel(context.Background()) and defer cancel() with t.Context() in nine test locations across cancel and graph tests.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A rabbit hops through test land with glee,
No more defer cancel() to flee!
t.Context() takes the wheel,
A cleaner, simpler deal—
The warren runs more tidy and free! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 is concise and accurately describes the main refactor from context.WithCancel to t.Context.
Description check ✅ Passed The description matches the required Summary section and provides background plus the motivation for the refactor.
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.

@JinHai-CN JinHai-CN added the ci Continue Integration label Jul 1, 2026
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (45fc7fe) to head (ce15fcc).
⚠️ Report is 17 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16509      +/-   ##
==========================================
- Coverage   94.56%   93.16%   -1.40%     
==========================================
  Files          10       10              
  Lines         717      717              
  Branches      118      118              
==========================================
- Hits          678      668      -10     
- Misses         25       29       +4     
- Partials       14       20       +6     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yingfeng
yingfeng merged commit fcf2ca8 into infiniflow:main Jul 1, 2026
14 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration ☯️ refactor Pull request that refactor/refine code size:XS This PR changes 0-9 lines, ignoring generated files. 🧪 test Pull requests that update test cases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants