Skip to content

refactor(test): context usage across the codebase#12435

Open
DariuszPorowski wants to merge 5 commits into
mainfrom
dp/greasy-quail-olive
Open

refactor(test): context usage across the codebase#12435
DariuszPorowski wants to merge 5 commits into
mainfrom
dp/greasy-quail-olive

Conversation

@DariuszPorowski

Copy link
Copy Markdown
Member
  • Removed the custom testcontext package and replaced its usage with the standard context from testing.T.
  • Updated various test files to use t.Context() instead of testcontext.New(t) or testcontext.NewWithCancel(t).
  • Ensured that all instances where a context was created for tests now utilize the built-in context methods, improving consistency and reducing dependency on the custom testcontext package.

Summary

Reason for change

Fixes #

How to test

File change summary

File Summary of change

- Removed the custom testcontext package and replaced its usage with the standard context from testing.T.
- Updated various test files to use t.Context() instead of testcontext.New(t) or testcontext.NewWithCancel(t).
- Ensured that all instances where a context was created for tests now utilize the built-in context methods, improving consistency and reducing dependency on the custom testcontext package.

Signed-off-by: Dariusz Porowski <3431813+DariuszPorowski@users.noreply.github.com>
@DariuszPorowski DariuszPorowski self-assigned this Jul 14, 2026
Copilot AI review requested due to automatic review settings July 14, 2026 22:13
@DariuszPorowski
DariuszPorowski requested review from a team as code owners July 14, 2026 22:13
@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copilot AI 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.

Pull request overview

This PR refactors the Radius Go test suite to use Go’s built-in (*testing.T).Context() instead of the repo’s custom test/testcontext helper, and updates contributor docs accordingly. The change standardizes how test-scoped contexts (and optional cancel/timeout wrappers) are created across unit, integration, and functional tests.

Changes:

  • Removed test/testcontext and migrated call sites from testcontext.New* to t.Context() plus context.WithCancel/WithTimeout where needed.
  • Updated a wide set of tests to consistently use the test lifetime context for API calls, controllers, and helpers.
  • Updated contributor documentation for test context usage and logging guidance.

Reviewed changes

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

Show a summary per file
File Description
test/validation/shared.go Switches credential assertion helper to use t.Context().
test/ucp/ucptest.go Uses context.WithCancel(t.Context()) for UCP test lifecycle context.
test/ucp/storetest/shared.go Replaces custom test context with context.WithCancel(t.Context()) in store shared tests.
test/ucp/queuetest/shared.go Replaces custom test context with context.WithCancel(t.Context()) in queue shared tests.
test/testcontext/testcontext.go Removes the custom testcontext implementation.
test/rp/rptest.go Migrates RP test harness context creation to t.Context() / context.WithCancel.
test/functional-portable/upgrade/upgrade_test.go Uses t.Context() for upgrade tests; fixes a minor indentation issue.
test/functional-portable/ucp/noncloud/tracked_resource_test.go Uses t.Context() for tracked resource functional test.
test/functional-portable/ucp/noncloud/resourceprovider_test.go Uses context.WithCancel(t.Context()) for provider registration test.
test/functional-portable/kubernetes/noncloud/kubernetes_test.go Uses t.Context() and context.WithCancel(t.Context()) in Kubernetes interop tests.
test/functional-portable/kubernetes/noncloud/flux_test.go Uses t.Context() in Flux integration helper.
test/functional-portable/kubernetes/noncloud/deploymenttemplate_test.go Uses t.Context() and context.WithCancel(t.Context()) throughout deploymenttemplate tests.
test/functional-portable/corerp/noncloud/api_test.go Uses context.WithCancel(t.Context()) for Core RP API tests.
test/functional-portable/cli/noncloud/group_delete_test.go Uses context.WithCancel(t.Context()) for CLI group delete test.
test/functional-portable/cli/noncloud/env_deploy_test.go Uses context.WithCancel(t.Context()) for CLI env deploy test.
test/functional-portable/cli/noncloud/env_delete_test.go Uses context.WithCancel(t.Context()) for CLI env delete test.
test/functional-portable/cli/noncloud/cli_test.go Migrates multiple CLI functional tests to context.WithCancel(t.Context()).
pkg/ucp/trackedresource/update_test.go Uses t.Context() for trackedresource updater unit tests.
pkg/ucp/proxy/types_test.go Uses t.Context() when setting request contexts in proxy tests.
pkg/ucp/proxy/async_test.go Uses t.Context() for async operation header tests.
pkg/ucp/proxy/arm_test.go Uses context.WithCancel(t.Context()) in ARM baseline tests.
pkg/ucp/integrationtests/testrp/sync.go Uses t.Context() in test RP sync router setup.
pkg/ucp/integrationtests/testrp/async.go Uses t.Context() and context.WithCancel(t.Context()) in async test RP setup.
pkg/ucp/frontend/controller/resourcegroups/util_test.go Uses t.Context() in ValidateDownstream tests.
pkg/ucp/frontend/controller/radius/proxy_test.go Uses t.Context() for controller tests and request preparation.
pkg/ucp/frontend/api/routes_test.go Uses t.Context() for route registration test.
pkg/ucp/backend/controller/resourcegroups/trackedresourceprocess_test.go Uses t.Context() for tracked resource process controller tests.
pkg/recipes/terraform/types_test.go Uses t.Context() for Terraform type/unit tests.
pkg/recipes/terraform/log_test.go Uses t.Context() for Terraform logging tests.
pkg/recipes/terraform/execute_test.go Uses t.Context() in Terraform execution config tests.
pkg/recipes/terraform/config/providers/kubernetes_test.go Uses t.Context() in Kubernetes provider config tests.
pkg/recipes/terraform/config/providers/azure_test.go Uses t.Context() in Azure provider config tests.
pkg/recipes/terraform/config/providers/aws_test.go Uses t.Context() in AWS provider config tests.
pkg/recipes/terraform/config/config_test.go Uses t.Context() across Terraform config unit tests.
pkg/recipes/engine/engine_test.go Uses t.Context() for recipe engine tests.
pkg/recipes/driver/terraform/terraform_test.go Uses t.Context() for Terraform driver tests.
pkg/recipes/driver/bicep/bicep_test.go Uses t.Context() for Bicep driver tests.
pkg/dynamicrp/integrationtest/dynamic/operations_test.go Uses t.Context() in dynamic RP operation tests.
pkg/dynamicrp/backend/controller/putinert_test.go Uses t.Context() for inert put controller test.
pkg/dynamicrp/backend/controller/deleteinert_test.go Uses t.Context() for inert delete controller test.
pkg/corerp/renderers/gateway/render_test.go Uses t.Context() in gateway renderer tests.
pkg/corerp/renderers/container/render_test.go Uses t.Context() across container renderer tests.
pkg/corerp/renderers/container/manifest_test.go Uses t.Context() in container manifest tests.
pkg/corerp/backend/deployment/deploymentprocessor_test.go Uses t.Context() throughout deployment processor tests.
pkg/controller/reconciler/shared_test.go Uses t.Context() in reconciler shared helpers.
pkg/controller/reconciler/recipe_webhook_test.go Uses t.Context() / context.WithCancel(t.Context()) in webhook tests and setup.
pkg/controller/reconciler/recipe_reconciler_test.go Uses t.Context() / context.WithCancel(t.Context()) in recipe reconciler tests and setup.
pkg/controller/reconciler/flux_controller_test.go Uses t.Context() / context.WithCancel(t.Context()) in flux controller tests and setup.
pkg/controller/reconciler/deploymenttemplate_reconciler_test.go Uses t.Context() / context.WithCancel(t.Context()) across deploymenttemplate reconciler tests and setup.
pkg/controller/reconciler/deploymentresource_reconciler_test.go Uses t.Context() / context.WithCancel(t.Context()) across deploymentresource reconciler tests and setup.
pkg/controller/reconciler/deployment_reconciler_test.go Uses t.Context() / context.WithCancel(t.Context()) across deployment reconciler tests and setup.
pkg/components/testhost/host.go Uses context.WithCancel(t.Context()) for host lifecycle in test host helper.
pkg/components/queue/apiserver/client_test.go Uses context.WithCancel(t.Context()) for API server queue client test.
pkg/components/hosting/hosting_test.go Uses context.WithTimeout(t.Context(), ...) to bound host tests.
pkg/components/database/postgres/postgresclient_test.go Uses context.WithCancel(t.Context()) for Postgres store tests.
pkg/components/database/apiserverstore/apiserverclient_test.go Uses context.WithCancel(t.Context()) for API server store tests.
pkg/cli/kubernetes/portforward/deployment_watcher_test.go Uses context.WithCancel(t.Context()) for watcher lifecycle control in tests.
pkg/cli/kubernetes/portforward/application_watcher_test.go Uses t.Context() / context.WithCancel(t.Context()) in watcher tests.
pkg/cli/credential/credential_management_test.go Uses context.WithCancel(t.Context()) across credential management tests.
pkg/cli/cmd/run/run_test.go Uses context.WithCancel(t.Context()) / t.Context() in rad run tests.
pkg/armrpc/rpctest/routers.go Uses t.Context() when configuring routers for RPC tests.
pkg/armrpc/frontend/server/handler_test.go Uses t.Context() for handler registration tests.
pkg/armrpc/frontend/defaultoperation/getoperationresult_test.go Uses t.Context() when building HTTP requests from JSON fixtures.
pkg/armrpc/builder/builder_test.go Uses t.Context() in async handler builder tests.
docs/contributing/contributing-code/contributing-code-tests/tests-logging.md Updates guidance to use t.Context() + standard cancellation/timeout wrappers.

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

Unit Tests

    2 files  ±0    454 suites  ±0   7m 29s ⏱️ +18s
5 870 tests ±0  5 868 ✅ ±0  2 💤 ±0  0 ❌ ±0 
7 073 runs  ±0  7 071 ✅ ±0  2 💤 ±0  0 ❌ ±0 

Results for commit e188157. ± Comparison against base commit 375f076.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

Functional Tests - corerp-cloud

30 tests  ±0   29 ✅ ±0   20m 59s ⏱️ +41s
 2 suites ±0    1 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit e188157. ± Comparison against base commit 375f076.

♻️ This comment has been updated with latest results.

@DariuszPorowski

Copy link
Copy Markdown
Member Author

@copilot fix issues discovered in the PR workflows run

Co-authored-by: DariuszPorowski <3431813+DariuszPorowski@users.noreply.github.com>

Copilot AI commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

@copilot fix issues discovered in the PR workflows run

Fixed in commit fix: replace missed testcontext.New(t) with t.Context() in proxy_test.go.

The CI failures (Go lint + unit tests) were both caused by a missed testcontext.New(t) call on line 126 of pkg/ucp/frontend/controller/radius/proxy_test.go. The testcontext package was removed as part of this refactor but this one call site was not updated. Replaced it with t.Context() to match the rest of the file.

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.45%. Comparing base (375f076) to head (e188157).

Files with missing lines Patch % Lines
pkg/ucp/integrationtests/testrp/async.go 0.00% 2 Missing ⚠️
pkg/components/testhost/host.go 0.00% 1 Missing ⚠️
pkg/ucp/integrationtests/testrp/sync.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12435      +/-   ##
==========================================
- Coverage   53.46%   53.45%   -0.01%     
==========================================
  Files         758      758              
  Lines       49254    49254              
==========================================
- Hits        26333    26329       -4     
- Misses      20475    20477       +2     
- Partials     2446     2448       +2     

☔ 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.

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown

Functional Tests - corerp-noncloud

180 tests  ±0   178 ✅ ±0   1h 23m 14s ⏱️ - 2m 26s
  3 suites ±0     2 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit e188157. ± Comparison against base commit 375f076.

♻️ This comment has been updated with latest results.

@radius-functional-tests

radius-functional-tests Bot commented Jul 15, 2026

Copy link
Copy Markdown

Radius functional test overview

🔍 Go to test action run

Click here to see the test run details
Name Value
Repository radius-project/radius
Commit ref e188157
Unique ID func5016d3f96f
Image tag pr-func5016d3f96f
  • Dapr: 1.14.4
  • Azure KeyVault CSI driver: 1.4.2
  • Azure Workload identity webhook: 1.3.0
  • Bicep recipe location ghcr.io/radius-project/dev/test/testrecipes/test-bicep-recipes/<name>:pr-func5016d3f96f
  • Terraform recipe location http://tf-module-server.radius-test-tf-module-server.svc.cluster.local/<name>.zip (in cluster)
  • applications-rp test image location: ghcr.io/radius-project/dev/applications-rp:pr-func5016d3f96f
  • dynamic-rp test image location: ghcr.io/radius-project/dev/dynamic-rp:pr-func5016d3f96f
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-func5016d3f96f
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-func5016d3f96f
  • deployment-engine test image location: ghcr.io/radius-project/deployment-engine:latest

Test Status

⌛ Building Radius and pushing container images for functional tests...
✅ Container images build succeeded
⌛ Publishing Bicep Recipes for functional tests...
✅ Recipe publishing succeeded
⌛ Starting corerp-cloud functional tests...
⌛ Starting ucp-cloud functional tests...
✅ ucp-cloud functional tests succeeded
✅ corerp-cloud functional tests succeeded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants