refactor(test): context usage across the codebase#12435
refactor(test): context usage across the codebase#12435DariuszPorowski wants to merge 5 commits into
Conversation
- 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>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
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/testcontextand migrated call sites fromtestcontext.New*tot.Context()pluscontext.WithCancel/WithTimeoutwhere 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. |
|
@copilot fix issues discovered in the PR workflows run |
Co-authored-by: DariuszPorowski <3431813+DariuszPorowski@users.noreply.github.com>
Fixed in commit The CI failures (Go lint + unit tests) were both caused by a missed |
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
Radius functional test overviewClick here to see the test run details
Test Status⌛ Building Radius and pushing container images for functional tests... |
Summary
Reason for change
Fixes #
How to test
File change summary