Skip to content

Refactor test cases to use context from testing.T#1182

Merged
zhenghaoz merged 1 commit intomasterfrom
context
Feb 27, 2026
Merged

Refactor test cases to use context from testing.T#1182
zhenghaoz merged 1 commit intomasterfrom
context

Conversation

@zhenghaoz
Copy link
Collaborator

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request refactors test cases across the codebase to use test-managed contexts (t.Context(), b.Context(), or suite.T().Context()) instead of manually created contexts (context.Background() or context.TODO()). This enables proper test timeout and cancellation propagation through the testing framework.

Changes:

  • Replace context.Background() and context.TODO() with t.Context() in standalone test functions
  • Replace context.Background() and context.TODO() with suite.T().Context() in testify suite tests
  • Replace context.Background() and context.TODO() with b.Context() in benchmark functions
  • Remove unused context package imports where no longer needed

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated no comments.

Show a summary per file
File Description
worker/worker_test.go Updated 17 test methods to use suite.T().Context() and 2 helper function calls to use t.Context()
worker/pipeline_test.go Updated 3 usages to suite.T().Context() and removed unused context import
storage/vectors/database_test.go Updated 3 test methods to use suite.T().Context() and removed unused context import
storage/data/no_database_test.go Updated standalone test to use t.Context() and removed unused context import
storage/data/mongodb_test.go Updated suite setup and benchmark to use suite.T().Context() and b.Context() respectively, removed unused context import
storage/data/database_test.go Updated 10 test methods to use suite.T().Context() and 2 benchmark functions to use b.Context()
storage/cache/redis_test.go Updated 5 test methods to use suite.T().Context() and 1 benchmark to use b.Context()
storage/cache/no_database_test.go Updated standalone test to use t.Context() and removed unused context import
storage/cache/mongodb_test.go Updated suite setup and benchmark to use suite.T().Context() and b.Context() respectively, removed unused context import
storage/cache/database_test.go Updated 11 test methods to use suite.T().Context() and 3 benchmark functions to use b.Context()
storage/blob/s3_test.go Updated test to use t.Context() and removed unused context import
storage/blob/gcs_test.go Updated test to use t.Context() and removed unused context import
storage/blob/azure_test.go Updated test to use t.Context() and removed unused context import
server/rest_test.go Updated 19 test methods to use suite.T().Context() and removed unused context import
model/ctr/model_test.go Updated 4 test functions to use t.Context() and removed unused context import
model/cf/model_test.go Updated 2 test functions to use t.Context() and removed unused context import
master/tasks_test.go Updated 11 test methods to use s.T().Context() and removed unused context import
master/rpc_test.go Updated 5 test functions and helper calls to use t.Context() and removed unused context import
master/rest_test.go Updated 19 test methods to use suite.T().Context() and removed unused context import
logics/recommend_test.go Updated 15 test method calls to use suite.T().Context() and removed unused context import
logics/chat_test.go Updated test to use t.Context() and removed unused context import
common/reranker/client_test.go Updated test to use suite.T().Context() and removed unused context import
common/parallel/parallel_test.go Updated 16 test functions to use t.Context() as base context for operations
common/mock/openai_test.go Updated 3 test methods to use suite.T().Context() and removed unused context import
client/client_test.go Updated 6 test methods to use suite.T().Context() and removed unused context import

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.66%. Comparing base (5a3cded) to head (057fdab).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1182      +/-   ##
==========================================
+ Coverage   72.64%   72.66%   +0.02%     
==========================================
  Files          87       87              
  Lines       16054    16054              
==========================================
+ Hits        11662    11666       +4     
+ Misses       3202     3198       -4     
  Partials     1190     1190              

☔ View full report in Codecov by Sentry.
📢 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.

@zhenghaoz zhenghaoz merged commit 5eb7e56 into master Feb 27, 2026
17 checks passed
@zhenghaoz zhenghaoz deleted the context branch February 27, 2026 12:19
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