Repository: kubernetes-sigs/kueue

Issue:
Add environment variable to control logging verbosity in integration tests
<!-- Please only use this template for submitting enhancement requests -->

**What would you like to be added**:
Add support to control logging verbosity in integration tests via environment variable.
**Why is this needed**:
Right now it's needed to change the code to change verbosity:
https://github.com/kubernetes-sigs/kueue/blob/f8015cb273f9115c34f9be32b35f7e1308c16459/test/integration/framework/framework.go#L72


Hints from issue comments:
@mimowo: /remove-kind feature
/kind cleanup
@tenzen-y: Shouldn't this ginkgo option enough?

```
  --vv 
    If set, emits with maximal verbosity - includes skipped and pending tests.
```@mbobrovskyi: > Shouldn't this ginkgo option enough?
> 
> ```
>   --vv 
>     If set, emits with maximal verbosity - includes skipped and pending tests.
> ```

The `--vv` flag increasing only ginkgo verbosity. 

We already have `API_LOG_LEVEL` variable and we are using it to change testEnv verbosity. 

https://github.com/kubernetes-sigs/kueue/blob/c5dae03dc28beb0d3f47fa1da08f1134140d49fb/test/integration/framework/framework.go#L93-L97

Maybe we should set `API_LOG_LEVEL` value on `ctrl.SetLogger()` as well.@mimowo: Yeah, I think we could reuse "API_LOG_LEVEL", but the name seems confusing as it already does more than the log level to api-server. Maybe we just rename `API_LOG_LEVEL` to `INTEGRATION_VLEVEL`, and use it for kube-apiserver and kueue test code?

IIUC `API_LOG_LEVEL` is only used for integration tests anyway. Another name could be `INTEGRATION_LOG_LEVEL`.@tenzen-y: > > Shouldn't this ginkgo option enough?
> > ```
> >   --vv 
> >     If set, emits with maximal verbosity - includes skipped and pending tests.
> > ```
> 
> The `--vv` flag increasing only ginkgo verbosity.
> 
> We already have `API_LOG_LEVEL` variable and we are using it to change testEnv verbosity.
> 
> [kueue/test/integration/framework/framework.go](https://github.com/kubernetes-sigs/kueue/blob/c5dae03dc28beb0d3f47fa1da08f1134140d49fb/test/integration/framework/framework.go#L93-L97)
> 
> Lines 93 to 97 in [c5dae03](/kubernetes-sigs/kueue/commit/c5dae03dc28beb0d3f47fa1da08f1134140d49fb)
> 
>  if level, err := strconv.Atoi(os.Getenv("API_LOG_LEVEL")); err == nil && level > 0 { 
>  	f.testEnv.ControlPlane.GetAPIServer().Configure().Append("v", strconv.Itoa(level)) 
>  	f.testEnv.ControlPlane.GetAPIServer().Out = ginkgo.GinkgoWriter 
>  	f.testEnv.ControlPlane.GetAPIServer().Err = ginkgo.GinkgoWriter 
>  } 
> Maybe we should set `API_LOG_LEVEL` value on `ctrl.SetLogger()` as well.

Good point, I agree with you@tenzen-y: > Yeah, I think we could reuse "API_LOG_LEVEL", but the name seems confusing as it already does more than the log level to api-server. Maybe we just rename `API_LOG_LEVEL` to `INTEGRATION_VLEVEL`, and use it for kube-apiserver and kueue test code?
> 
> IIUC `API_LOG_LEVEL` is only used for integration tests anyway. Another name could be `INTEGRATION_LOG_LEVEL`.

+1@mbobrovskyi: /assign@mbobrovskyi: > Yeah, I think we could reuse "API_LOG_LEVEL", but the name seems confusing as it already does more than the log level to api-server. Maybe we just rename `API_LOG_LEVEL` to `INTEGRATION_VLEVEL`, and use it for kube-apiserver and kueue test code?
> 
> IIUC `API_LOG_LEVEL` is only used for integration tests anyway. Another name could be `INTEGRATION_LOG_LEVEL`.

It also used on E2E tests.

https://github.com/kubernetes-sigs/kueue/blob/c5dae03dc28beb0d3f47fa1da08f1134140d49fb/test/e2e/singlecluster/suite_test.go#L61@mimowo: Is the `API_LOG_LEVEL` used in e2e tests? Maybe for e2e tests we could have E2ETEST_LOG_LEVEL? @mbobrovskyi: > Is the `API_LOG_LEVEL` used in e2e tests? Maybe for e2e tests we could have E2ETEST_LOG_LEVEL?

Do you think we need to split between E2E and integration?@mimowo: Not necessarily, do you have an alternative proposal? @mbobrovskyi: Umm, I think I understand what the `API_LOG_LEVEL` variable does.

https://github.com/kubernetes-sigs/kueue/blob/c5dae03dc28beb0d3f47fa1da08f1134140d49fb/Makefile-test.mk#L45-L47

This isn’t a log level; it’s a verbosity level, and it’s disabled by default.

So we still need to keep it and create a new one.@mbobrovskyi: > Not necessarily, do you have an alternative proposal?

I think `LOG_LEVEL` is good.@mimowo: Maybe `TEST_LOG_LEVEL`?

Solution patch:
diff --git a/site/content/en/docs/contribution_guidelines/testing.md b/site/content/en/docs/contribution_guidelines/testing.md
index b231ddb04..45e9799df 100644
--- a/site/content/en/docs/contribution_guidelines/testing.md
+++ b/site/content/en/docs/contribution_guidelines/testing.md
@@ -53,21 +53,14 @@ make test-integration
 
 For running a subset of tests, see [Running subset of tests](#running-subset-of-integration-or-e2e-tests).
 
-### Increase logging verbosity
-You can change log level in the framework (for example, change -3 to -5 to increase verbosity):
-https://github.com/kubernetes-sigs/kueue/blob/f8015cb273f9115c34f9be32b35f7e1308c16459/test/integration/framework/framework.go#L72:
-```go
-var setupLogger = sync.OnceFunc(func() {
-	ctrl.SetLogger(util.NewTestingLogger(ginkgo.GinkgoWriter, -3))
-})
-```
-
 ## Running e2e tests using custom build
 ```shell
 make kind-image-build
 make test-e2e
 make test-tas-e2e
 make test-e2e-customconfigs
+make test-e2e-certmanager
+make test-e2e-kueueviz
 make test-multikueue-e2e
 ```
 
@@ -78,6 +71,10 @@ E2E_KIND_VERSION=kindest/node:v1.32.0 make test-e2e
 
 For running a subset of tests, see [Running subset of tests](#running-subset-of-integration-or-e2e-tests).
 
+## Increase logging verbosity
+You can change log level (for example, set -5 to increase verbosity) using `TEST_LOG_LEVEL` variables.
+By default, `TEST_LOG_LEVEL=-3`.
+
 ## Debug tests in VSCode
 It is possible to debug unit and integration tests in VSCode.
 You need to have the [Go extension](https://marketplace.visualstudio.com/items?itemName=golang.Go) installed.



Test patch:
diff --git a/cmd/importer/pod/check_test.go b/cmd/importer/pod/check_test.go
index 3a9ec570a..bf8ca8452 100644
--- a/cmd/importer/pod/check_test.go
+++ b/cmd/importer/pod/check_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package pod
 
 import (
-	"context"
 	"testing"
 
 	"github.com/google/go-cmp/cmp"
@@ -156,7 +155,7 @@ func TestCheckNamespace(t *testing.T) {
 			builder = builder.WithLists(&podsList, &cqList, &lqList, &rfList)
 
 			client := builder.Build()
-			ctx := context.Background()
+			ctx := t.Context()
 
 			mpc, _ := util.LoadImportCache(ctx, client, []string{testingNamespace}, tc.mapping, nil)
 			gotErr := Check(ctx, client, mpc, 8)
diff --git a/cmd/importer/pod/import_test.go b/cmd/importer/pod/import_test.go
index c72181797..a57b63b13 100644
--- a/cmd/importer/pod/import_test.go
+++ b/cmd/importer/pod/import_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package pod
 
 import (
-	"context"
 	"testing"
 
 	"github.com/google/go-cmp/cmp"
@@ -178,7 +177,7 @@ func TestImportNamespace(t *testing.T) {
 				WithLists(&podsList, &cqList, &lqList)
 
 			client := builder.Build()
-			ctx := context.Background()
+			ctx := t.Context()
 
 			mpc, _ := util.LoadImportCache(ctx, client, []string{testingNamespace}, tc.mapping, tc.addLabels)
 			gotErr := Import(ctx, client, mpc, 8)
diff --git a/cmd/kueuectl/app/create/create_resourceflavor_test.go b/cmd/kueuectl/app/create/create_resourceflavor_test.go
index 53c29711b..88743a47b 100644
--- a/cmd/kueuectl/app/create/create_resourceflavor_test.go
+++ b/cmd/kueuectl/app/create/create_resourceflavor_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package create
 
 import (
-	"context"
 	"fmt"
 	"testing"
 
@@ -358,7 +357,7 @@ func TestResourceFlavorCmd(t *testing.T) {
 				t.Errorf("Unexpected output (-want/+got)\n%s", diff)
 			}
 
-			gotRf, err := clientset.KueueV1beta1().ResourceFlavors().Get(context.Background(), tc.rfName, metav1.GetOptions{})
+			gotRf, err := clientset.KueueV1beta1().ResourceFlavors().Get(t.Context(), tc.rfName, metav1.GetOptions{})
 			if client.IgnoreNotFound(err) != nil {
 				t.Error(err)
 				return
diff --git a/cmd/kueuectl/app/delete/delete_workload_test.go b/cmd/kueuectl/app/delete/delete_workload_test.go
index ab55fab09..07dc7f9df 100644
--- a/cmd/kueuectl/app/delete/delete_workload_test.go
+++ b/cmd/kueuectl/app/delete/delete_workload_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package delete
 
 import (
-	"context"
 	"slices"
 	"testing"
 
@@ -353,7 +352,7 @@ Do you want to proceed (y/n)? jobs.batch/j1 deleted
 				t.Errorf("Unexpected error output (-want/+got)\n%s", diff)
 			}
 
-			gotWorkloadList, err := clientset.KueueV1beta1().Workloads(tc.ns).List(context.Background(), metav1.ListOptions{})
+			gotWorkloadList, err := clientset.KueueV1beta1().Workloads(tc.ns).List(t.Context(), metav1.ListOptions{})
 			if err != nil {
 				t.Fatal(err)
 			}
@@ -366,7 +365,7 @@ Do you want to proceed (y/n)? jobs.batch/j1 deleted
 			}
 
 			unstructured, err := dynamicClient.Resource(mapping.Resource).Namespace(metav1.NamespaceDefault).
-				List(context.Background(), metav1.ListOptions{})
+				List(t.Context(), metav1.ListOptions{})
 			if err != nil {
 				t.Error(err)
 				return
diff --git a/pkg/cache/cache_test.go b/pkg/cache/cache_test.go
index 33528bc28..7bda6c681 100644
--- a/pkg/cache/cache_test.go
+++ b/pkg/cache/cache_test.go
@@ -88,7 +88,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
 				NodeLabel("cpuType", "default").
 				Obj())
 		for _, c := range initialClusterQueues {
-			if err := cache.AddClusterQueue(context.Background(), &c); err != nil {
+			if err := cache.AddClusterQueue(t.Context(), &c); err != nil {
 				return fmt.Errorf("failed adding ClusterQueue: %w", err)
 			}
 		}
@@ -178,7 +178,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
 					ReclaimWithinCohort: kueue.PreemptionPolicyLowerPriority,
 					WithinClusterQueue:  kueue.PreemptionPolicyLowerPriority,
 				}).Obj()
-				if err := cache.AddClusterQueue(context.Background(), cq); err != nil {
+				if err := cache.AddClusterQueue(t.Context(), cq); err != nil {
 					return fmt.Errorf("failed to add ClusterQueue: %w", err)
 				}
 				return nil
@@ -202,7 +202,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
 			name: "add ClusterQueue with fair sharing weight",
 			operation: func(cache *Cache) error {
 				cq := utiltesting.MakeClusterQueue("foo").FairWeight(resource.MustParse("2")).Obj()
-				if err := cache.AddClusterQueue(context.Background(), cq); err != nil {
+				if err := cache.AddClusterQueue(t.Context(), cq); err != nil {
 					return fmt.Errorf("failed to add ClusterQueue: %w", err)
 				}
 				return nil
@@ -223,7 +223,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
 			name: "add flavors after queue capacities",
 			operation: func(cache *Cache) error {
 				for _, c := range initialClusterQueues {
-					if err := cache.AddClusterQueue(context.Background(), &c); err != nil {
+					if err := cache.AddClusterQueue(t.Context(), &c); err != nil {
 						return fmt.Errorf("failed adding ClusterQueue: %w", err)
 					}
 				}
@@ -414,7 +414,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
 					NamespaceSelector(nil).
 					Obj()
 
-				if err := cache.AddClusterQueue(context.Background(), cq); err != nil {
+				if err := cache.AddClusterQueue(t.Context(), cq); err != nil {
 					return fmt.Errorf("failed adding ClusterQueue: %w", err)
 				}
 
@@ -680,7 +680,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
 		{
 			name: "Add ClusterQueue with multiple resource groups",
 			operation: func(cache *Cache) error {
-				err := cache.AddClusterQueue(context.Background(),
+				err := cache.AddClusterQueue(t.Context(),
 					utiltesting.MakeClusterQueue("foo").
 						ResourceGroup(
 							*utiltesting.MakeFlavorQuotas("foo").
@@ -717,7 +717,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
 		{
 			name: "add cluster queue with missing check",
 			operation: func(cache *Cache) error {
-				err := cache.AddClusterQueue(context.Background(),
+				err := cache.AddClusterQueue(t.Context(),
 					utiltesting.MakeClusterQueue("foo").
 						AdmissionChecks("check1", "check2").
 						Obj())
@@ -746,7 +746,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
 		{
 			name: "add check after queue creation",
 			operation: func(cache *Cache) error {
-				err := cache.AddClusterQueue(context.Background(),
+				err := cache.AddClusterQueue(t.Context(),
 					utiltesting.MakeClusterQueue("foo").
 						AdmissionChecks("check1", "check2").
 						Obj())
@@ -780,7 +780,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
 			operation: func(cache *Cache) error {
 				cache.AddOrUpdateAdmissionCheck(utiltesting.MakeAdmissionCheck("check1").Active(metav1.ConditionTrue).Obj())
 				cache.AddOrUpdateAdmissionCheck(utiltesting.MakeAdmissionCheck("check2").Active(metav1.ConditionTrue).Obj())
-				err := cache.AddClusterQueue(context.Background(),
+				err := cache.AddClusterQueue(t.Context(),
 					utiltesting.MakeClusterQueue("foo").
 						AdmissionChecks("check1", "check2").
 						Obj())
@@ -813,7 +813,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
 			operation: func(cache *Cache) error {
 				cache.AddOrUpdateAdmissionCheck(utiltesting.MakeAdmissionCheck("check1").Active(metav1.ConditionTrue).Obj())
 				cache.AddOrUpdateAdmissionCheck(utiltesting.MakeAdmissionCheck("check2").Active(metav1.ConditionTrue).Obj())
-				err := cache.AddClusterQueue(context.Background(),
+				err := cache.AddClusterQueue(t.Context(),
 					utiltesting.MakeClusterQueue("foo").
 						AdmissionChecks("check1", "check2").
 						Obj())
@@ -858,7 +858,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
 			},
 			operation: func(cache *Cache) error {
 				cache.AddOrUpdateResourceFlavor(utiltesting.MakeResourceFlavor("f1").Obj())
-				err := cache.AddClusterQueue(context.Background(),
+				err := cache.AddClusterQueue(t.Context(),
 					utiltesting.MakeClusterQueue("cq1").
 						ResourceGroup(kueue.FlavorQuotas{
 							Name: "f1",
@@ -973,7 +973,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
 						},
 					).
 					Obj()
-				return cache.AddClusterQueue(context.Background(), cq)
+				return cache.AddClusterQueue(t.Context(), cq)
 			},
 			wantClusterQueues: map[kueue.ClusterQueueReference]*clusterQueue{
 				"foo": {
@@ -1037,7 +1037,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
 						},
 					).
 					Obj()
-				return cache.AddClusterQueue(context.Background(), cq)
+				return cache.AddClusterQueue(t.Context(), cq)
 			},
 			wantClusterQueues: map[kueue.ClusterQueueReference]*clusterQueue{
 				"foo": {
@@ -1077,7 +1077,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
 				cohort := utiltesting.MakeCohort("cohort").Obj()
 				_ = cache.AddOrUpdateCohort(cohort)
 
-				_ = cache.AddClusterQueue(context.Background(),
+				_ = cache.AddClusterQueue(t.Context(),
 					utiltesting.MakeClusterQueue("cq").Cohort("cohort").Obj())
 				cache.DeleteCohort(kueue.CohortReference(cohort.Name))
 				return nil
@@ -1673,7 +1673,7 @@ func TestCacheWorkloadOperations(t *testing.T) {
 			cache := New(cl)
 
 			for _, c := range clusterQueues {
-				if err := cache.AddClusterQueue(context.Background(), &c); err != nil {
+				if err := cache.AddClusterQueue(t.Context(), &c); err != nil {
 					t.Fatalf("Failed adding clusterQueue: %v", err)
 				}
 			}
@@ -2030,7 +2030,7 @@ func TestClusterQueueUsage(t *testing.T) {
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
 			cache := New(utiltesting.NewFakeClient())
-			ctx := context.Background()
+			ctx := t.Context()
 			err := cache.AddClusterQueue(ctx, tc.clusterQueue)
 			if err != nil {
 				t.Fatalf("Adding ClusterQueue: %v", err)
@@ -2261,7 +2261,7 @@ func TestLocalQueueUsage(t *testing.T) {
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
 			cache := New(utiltesting.NewFakeClient())
-			ctx := context.Background()
+			ctx := t.Context()
 			if tc.cq != nil {
 				if err := cache.AddClusterQueue(ctx, tc.cq); err != nil {
 					t.Fatalf("Adding ClusterQueue: %v", err)
@@ -2720,7 +2720,7 @@ func TestCacheQueueOperations(t *testing.T) {
 		t.Run(name, func(t *testing.T) {
 			cl := utiltesting.NewFakeClient()
 			cache := New(cl)
-			ctx := context.Background()
+			ctx := t.Context()
 			for i, op := range tc.ops {
 				if err := op(ctx, cl, cache); err != nil {
 					t.Fatalf("Running op %d: %v", i, err)
@@ -2795,7 +2795,7 @@ func TestClusterQueuesUsingFlavor(t *testing.T) {
 			cache.AddOrUpdateResourceFlavor(aarch64Rf)
 
 			for _, cq := range tc.clusterQueues {
-				if err := cache.AddClusterQueue(context.Background(), cq); err != nil {
+				if err := cache.AddClusterQueue(t.Context(), cq); err != nil {
 					t.Errorf("failed to add clusterQueue %s", cq.Name)
 				}
 			}
@@ -2831,7 +2831,7 @@ func TestMatchingClusterQueues(t *testing.T) {
 
 	cache := New(utiltesting.NewFakeClient())
 	for _, cq := range clusterQueues {
-		if err := cache.AddClusterQueue(context.Background(), cq); err != nil {
+		if err := cache.AddClusterQueue(t.Context(), cq); err != nil {
 			t.Errorf("failed to add clusterQueue %s", cq.Name)
 		}
 	}
@@ -2845,7 +2845,7 @@ func TestMatchingClusterQueues(t *testing.T) {
 // TestWaitForPodsReadyCancelled ensures that the WaitForPodsReady call does not block when the context is closed.
 func TestWaitForPodsReadyCancelled(t *testing.T) {
 	cache := New(utiltesting.NewFakeClient(), WithPodsReadyTracking(true))
-	ctx, cancel := context.WithCancel(context.Background())
+	ctx, cancel := context.WithCancel(t.Context())
 	defer cancel()
 	log := ctrl.LoggerFrom(ctx)
 
@@ -3103,7 +3103,7 @@ func TestCachePodsReadyForAllAdmittedWorkloads(t *testing.T) {
 	for _, tc := range tests {
 		t.Run(tc.name, func(t *testing.T) {
 			cache := New(cl, WithPodsReadyTracking(true))
-			ctx := context.Background()
+			ctx := t.Context()
 			log := ctrl.LoggerFrom(ctx)
 
 			for _, c := range clusterQueues {
@@ -3316,7 +3316,7 @@ func TestClusterQueuesUsingAdmissionChecks(t *testing.T) {
 			}
 
 			for _, cq := range tc.clusterQueues {
-				if err := cache.AddClusterQueue(context.Background(), cq); err != nil {
+				if err := cache.AddClusterQueue(t.Context(), cq); err != nil {
 					t.Errorf("failed to add clusterQueue %s", cq.Name)
 				}
 			}
@@ -3431,7 +3431,7 @@ func TestClusterQueueReadiness(t *testing.T) {
 				cache.AddOrUpdateAdmissionCheck(ac)
 			}
 			for _, cq := range tc.clusterQueues {
-				if err := cache.AddClusterQueue(context.Background(), cq); err != nil {
+				if err := cache.AddClusterQueue(t.Context(), cq); err != nil {
 					t.Errorf("failed to add clusterQueue %q: %v", cq.Name, err)
 				}
 			}
@@ -3488,7 +3488,7 @@ func TestCohortCycles(t *testing.T) {
 	})
 	t.Run("clusterqueue add and update return error when cohort has cycle", func(t *testing.T) {
 		cache := New(utiltesting.NewFakeClient())
-		ctx := context.Background()
+		ctx := t.Context()
 		cohortA := utiltesting.MakeCohort("cohort-a").Parent("cohort-b").Obj()
 		if err := cache.AddOrUpdateCohort(cohortA); err != nil {
 			t.Fatal("Expected success as no cycle yet")
@@ -3526,7 +3526,7 @@ func TestCohortCycles(t *testing.T) {
 
 	t.Run("clusterqueue leaving cohort with cycle successfully updates new cohort", func(t *testing.T) {
 		cache := New(utiltesting.NewFakeClient())
-		ctx := context.Background()
+		ctx := t.Context()
 		cycleCohort := utiltesting.MakeCohort("cycle").Parent("cycle").Obj()
 		if err := cache.AddOrUpdateCohort(cycleCohort); err == nil {
 			t.Fatal("Expected failure")
@@ -3570,7 +3570,7 @@ func TestCohortCycles(t *testing.T) {
 
 	t.Run("clusterqueue joining cohort with cycle successfully updates old cohort", func(t *testing.T) {
 		cache := New(utiltesting.NewFakeClient())
-		ctx := context.Background()
+		ctx := t.Context()
 		cycleCohort := utiltesting.MakeCohort("cycle").Parent("cycle").Obj()
 		if err := cache.AddOrUpdateCohort(cycleCohort); err == nil {
 			t.Fatal("Expected failure")
diff --git a/pkg/cache/resource_node_test.go b/pkg/cache/resource_node_test.go
index 3b5454895..f99062d9e 100644
--- a/pkg/cache/resource_node_test.go
+++ b/pkg/cache/resource_node_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package cache
 
 import (
-	"context"
 	"testing"
 
 	"github.com/google/go-cmp/cmp"
@@ -46,10 +45,10 @@ func TestCohortLendable(t *testing.T) {
 		).Cohort("test-cohort").
 		ClusterQueue
 
-	if err := cache.AddClusterQueue(context.Background(), &cq1); err != nil {
+	if err := cache.AddClusterQueue(t.Context(), &cq1); err != nil {
 		t.Fatal("Failed to add CQ to cache", err)
 	}
-	if err := cache.AddClusterQueue(context.Background(), &cq2); err != nil {
+	if err := cache.AddClusterQueue(t.Context(), &cq2); err != nil {
 		t.Fatal("Failed to add CQ to cache", err)
 	}
 
diff --git a/pkg/cache/resource_test.go b/pkg/cache/resource_test.go
index b9dda5131..e481148b7 100644
--- a/pkg/cache/resource_test.go
+++ b/pkg/cache/resource_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package cache
 
 import (
-	"context"
 	"testing"
 
 	"github.com/google/go-cmp/cmp"
@@ -362,7 +361,7 @@ func TestAvailable(t *testing.T) {
 
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
-			ctx := context.Background()
+			ctx := t.Context()
 			cache := New(utiltesting.NewFakeClient())
 			cache.AddOrUpdateResourceFlavor(utiltesting.MakeResourceFlavor("red").Obj())
 			cache.AddOrUpdateResourceFlavor(utiltesting.MakeResourceFlavor("blue").Obj())
diff --git a/pkg/cache/snapshot_test.go b/pkg/cache/snapshot_test.go
index 43fcd5f87..b4b975664 100644
--- a/pkg/cache/snapshot_test.go
+++ b/pkg/cache/snapshot_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package cache
 
 import (
-	"context"
 	"testing"
 
 	"github.com/google/go-cmp/cmp"
@@ -988,7 +987,7 @@ func TestSnapshotAddRemoveWorkload(t *testing.T) {
 			Obj(),
 	}
 
-	ctx := context.Background()
+	ctx := t.Context()
 	cl := utiltesting.NewClientBuilder().WithLists(&kueue.WorkloadList{Items: workloads}).Build()
 
 	cqCache := New(cl)
@@ -1282,7 +1281,7 @@ func TestSnapshotAddRemoveWorkloadWithLendingLimit(t *testing.T) {
 			Obj(),
 	}
 
-	ctx := context.Background()
+	ctx := t.Context()
 	cl := utiltesting.NewClientBuilder().WithLists(&kueue.WorkloadList{Items: workloads}).Build()
 
 	cqCache := New(cl)
diff --git a/pkg/controller/admissionchecks/multikueue/admissioncheck_test.go b/pkg/controller/admissionchecks/multikueue/admissioncheck_test.go
index 7d2f294c0..2d776a371 100644
--- a/pkg/controller/admissionchecks/multikueue/admissioncheck_test.go
+++ b/pkg/controller/admissionchecks/multikueue/admissioncheck_test.go
@@ -280,7 +280,7 @@ func TestReconcile(t *testing.T) {
 			if tc.acValidationRulesEnabled {
 				features.SetFeatureGateDuringTest(t, features.AdmissionCheckValidationRules, true)
 			}
-			builder, ctx := getClientBuilder()
+			builder := getClientBuilder(t.Context())
 
 			builder = builder.WithLists(
 				&kueue.AdmissionCheckList{Items: tc.checks},
@@ -297,13 +297,13 @@ func TestReconcile(t *testing.T) {
 			helper, _ := newMultiKueueStoreHelper(c)
 			reconciler := newACReconciler(c, helper)
 
-			_, gotErr := reconciler.Reconcile(ctx, reconcile.Request{NamespacedName: types.NamespacedName{Name: tc.reconcileFor}})
+			_, gotErr := reconciler.Reconcile(t.Context(), reconcile.Request{NamespacedName: types.NamespacedName{Name: tc.reconcileFor}})
 			if diff := cmp.Diff(tc.wantError, gotErr); diff != "" {
 				t.Errorf("unexpected error (-want/+got):\n%s", diff)
 			}
 
 			checks := &kueue.AdmissionCheckList{}
-			listErr := c.List(ctx, checks)
+			listErr := c.List(t.Context(), checks)
 
 			if listErr != nil {
 				t.Errorf("unexpected list checks error: %s", listErr)
diff --git a/pkg/controller/admissionchecks/multikueue/fswatch_test.go b/pkg/controller/admissionchecks/multikueue/fswatch_test.go
index 98e971582..28b56bcbd 100644
--- a/pkg/controller/admissionchecks/multikueue/fswatch_test.go
+++ b/pkg/controller/admissionchecks/multikueue/fswatch_test.go
@@ -143,7 +143,7 @@ func TestFSWatch(t *testing.T) {
 					t.Fatalf("unexpected prepare error: %s", err)
 				}
 			}
-			ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+			ctx, cancel := context.WithTimeout(t.Context(), time.Second)
 			watcher := newKubeConfigFSWatcher()
 
 			// start the recorder
@@ -193,7 +193,7 @@ func TestFSWatch(t *testing.T) {
 }
 
 func TestFSWatchAddRm(t *testing.T) {
-	ctx, cancel := context.WithCancel(context.Background())
+	ctx, cancel := context.WithCancel(t.Context())
 	defer cancel()
 	basePath := t.TempDir()
 	f1Path := filepath.Join(basePath, "file.one")
diff --git a/pkg/controller/admissionchecks/multikueue/indexer_test.go b/pkg/controller/admissionchecks/multikueue/indexer_test.go
index 082dd203e..1717b7d43 100644
--- a/pkg/controller/admissionchecks/multikueue/indexer_test.go
+++ b/pkg/controller/admissionchecks/multikueue/indexer_test.go
@@ -38,7 +38,7 @@ const (
 	TestNamespace = "ns"
 )
 
-func getClientBuilder() (*fake.ClientBuilder, context.Context) {
+func getClientBuilder(ctx context.Context) *fake.ClientBuilder {
 	scheme := runtime.NewScheme()
 	utilruntime.Must(clientgoscheme.AddToScheme(scheme))
 	utilruntime.Must(kueue.AddToScheme(scheme))
@@ -51,10 +51,9 @@ func getClientBuilder() (*fake.ClientBuilder, context.Context) {
 		return nil
 	}))
 
-	ctx := context.Background()
 	builder := fake.NewClientBuilder().WithScheme(scheme).WithObjects(utiltesting.MakeNamespace(TestNamespace))
 	_ = SetupIndexer(ctx, utiltesting.AsIndexer(builder), TestNamespace)
-	return builder, ctx
+	return builder
 }
 
 func TestListMultiKueueClustersUsingKubeConfig(t *testing.T) {
@@ -91,17 +90,17 @@ func TestListMultiKueueClustersUsingKubeConfig(t *testing.T) {
 	}
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
-			builder, ctx := getClientBuilder()
+			builder := getClientBuilder(t.Context())
 			k8sclient := builder.Build()
 			for _, req := range tc.clusters {
-				if err := k8sclient.Create(ctx, req); err != nil {
+				if err := k8sclient.Create(t.Context(), req); err != nil {
 					t.Fatalf("Unable to create %q cluster: %v", client.ObjectKeyFromObject(req), err)
 				}
 			}
 
 			lst := &kueue.MultiKueueClusterList{}
 
-			gotListErr := k8sclient.List(ctx, lst, tc.filter)
+			gotListErr := k8sclient.List(t.Context(), lst, tc.filter)
 			if diff := cmp.Diff(tc.wantListError, gotListErr); diff != "" {
 				t.Errorf("unexpected list error (-want/+got):\n%s", diff)
 			}
@@ -148,17 +147,17 @@ func TestListMultiKueueConfigsUsingMultiKueueClusters(t *testing.T) {
 	}
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
-			builder, ctx := getClientBuilder()
+			builder := getClientBuilder(t.Context())
 			k8sclient := builder.Build()
 			for _, config := range tc.configs {
-				if err := k8sclient.Create(ctx, config); err != nil {
+				if err := k8sclient.Create(t.Context(), config); err != nil {
 					t.Fatalf("Unable to create %q config: %v", client.ObjectKeyFromObject(config), err)
 				}
 			}
 
 			lst := &kueue.MultiKueueConfigList{}
 
-			gotListErr := k8sclient.List(ctx, lst, tc.filter)
+			gotListErr := k8sclient.List(t.Context(), lst, tc.filter)
 			if diff := cmp.Diff(tc.wantListError, gotListErr); diff != "" {
 				t.Errorf("unexpected list error (-want/+got):\n%s", diff)
 			}
diff --git a/pkg/controller/admissionchecks/multikueue/multikueuecluster_test.go b/pkg/controller/admissionchecks/multikueue/multikueuecluster_test.go
index 767c4696a..66f0bf197 100644
--- a/pkg/controller/admissionchecks/multikueue/multikueuecluster_test.go
+++ b/pkg/controller/admissionchecks/multikueue/multikueuecluster_test.go
@@ -48,31 +48,33 @@ var (
 	errCannotWatch   = errors.New("client cannot watch")
 )
 
-func fakeClientBuilder(kubeconfig []byte, _ client.Options) (client.WithWatch, error) {
-	if string(kubeconfig) == "invalid" {
-		return nil, errInvalidConfig
+func fakeClientBuilder(ctx context.Context) func([]byte, client.Options) (client.WithWatch, error) {
+	return func(kubeconfig []byte, _ client.Options) (client.WithWatch, error) {
+		if string(kubeconfig) == "invalid" {
+			return nil, errInvalidConfig
+		}
+		b := getClientBuilder(ctx)
+		b = b.WithInterceptorFuncs(interceptor.Funcs{
+			Watch: func(ctx context.Context, client client.WithWatch, obj client.ObjectList, opts ...client.ListOption) (watch.Interface, error) {
+				if string(kubeconfig) == "nowatch" {
+					return nil, errCannotWatch
+				}
+				return client.Watch(ctx, obj, opts...)
+			},
+		})
+		return b.Build(), nil
 	}
-	b, _ := getClientBuilder()
-	b = b.WithInterceptorFuncs(interceptor.Funcs{
-		Watch: func(ctx context.Context, client client.WithWatch, obj client.ObjectList, opts ...client.ListOption) (watch.Interface, error) {
-			if string(kubeconfig) == "nowatch" {
-				return nil, errCannotWatch
-			}
-			return client.Watch(ctx, obj, opts...)
-		},
-	})
-	return b.Build(), nil
 }
 
-func newTestClient(config string, watchCancel func()) *remoteClient {
-	b, _ := getClientBuilder()
+func newTestClient(ctx context.Context, config string, watchCancel func()) *remoteClient {
+	b := getClientBuilder(ctx)
 	localClient := b.Build()
 	ret := &remoteClient{
 		kubeconfig:  []byte(config),
 		localClient: localClient,
 		watchCancel: watchCancel,
 
-		builderOverride: fakeClientBuilder,
+		builderOverride: fakeClientBuilder(ctx),
 	}
 	return ret
 }
@@ -146,7 +148,7 @@ func TestUpdateConfig(t *testing.T) {
 				makeTestSecret("worker1", "worker1 kubeconfig"),
 			},
 			remoteClients: map[string]*remoteClient{
-				"worker1": newTestClient("worker1 old kubeconfig", cancelCalled),
+				"worker1": newTestClient(t.Context(), "worker1 old kubeconfig", cancelCalled),
 			},
 			wantClusters: []kueue.MultiKueueCluster{
 				*utiltesting.MakeMultiKueueCluster("worker1").
@@ -171,7 +173,7 @@ func TestUpdateConfig(t *testing.T) {
 					Obj(),
 			},
 			remoteClients: map[string]*remoteClient{
-				"worker1": newTestClient("worker1 old kubeconfig", cancelCalled),
+				"worker1": newTestClient(t.Context(), "worker1 old kubeconfig", cancelCalled),
 			},
 			wantClusters: []kueue.MultiKueueCluster{
 				*utiltesting.MakeMultiKueueCluster("worker1").
@@ -199,10 +201,10 @@ func TestUpdateConfig(t *testing.T) {
 				makeTestSecret("worker1", "invalid"),
 			},
 			remoteClients: map[string]*remoteClient{
-				"worker1": newTestClient("worker1 old kubeconfig", cancelCalled),
+				"worker1": newTestClient(t.Context(), "worker1 old kubeconfig", cancelCalled),
 			},
 			wantRemoteClients: map[string]*remoteClient{
-				"worker1": newTestClient("invalid", nil),
+				"worker1": newTestClient(t.Context(), "invalid", nil),
 			},
 			wantClusters: []kueue.MultiKueueCluster{
 				*utiltesting.MakeMultiKueueCluster("worker1").
@@ -222,7 +224,7 @@ func TestUpdateConfig(t *testing.T) {
 					Obj(),
 			},
 			remoteClients: map[string]*remoteClient{
-				"worker1": newTestClient("worker1 old kubeconfig", cancelCalled),
+				"worker1": newTestClient(t.Context(), "worker1 old kubeconfig", cancelCalled),
 			},
 			wantClusters: []kueue.MultiKueueCluster{
 				*utiltesting.MakeMultiKueueCluster("worker1").
@@ -242,8 +244,8 @@ func TestUpdateConfig(t *testing.T) {
 					Obj(),
 			},
 			remoteClients: map[string]*remoteClient{
-				"worker1": newTestClient("worker1 kubeconfig", cancelCalled),
-				"worker2": newTestClient("worker2 kubeconfig", cancelCalled),
+				"worker1": newTestClient(t.Context(), "worker1 kubeconfig", cancelCalled),
+				"worker2": newTestClient(t.Context(), "worker2 kubeconfig", cancelCalled),
 			},
 			wantClusters: []kueue.MultiKueueCluster{
 				*utiltesting.MakeMultiKueueCluster("worker1").
@@ -270,10 +272,10 @@ func TestUpdateConfig(t *testing.T) {
 				makeTestSecret("worker1", "nowatch"),
 			},
 			remoteClients: map[string]*remoteClient{
-				"worker1": newTestClient("worker1 old kubeconfig", cancelCalled),
+				"worker1": newTestClient(t.Context(), "worker1 old kubeconfig", cancelCalled),
 			},
 			wantRemoteClients: map[string]*remoteClient{
-				"worker1": setReconnectState(newTestClient("nowatch", nil), 1),
+				"worker1": setReconnectState(newTestClient(t.Context(), "nowatch", nil), 1),
 			},
 			wantClusters: []kueue.MultiKueueCluster{
 				*utiltesting.MakeMultiKueueCluster("worker1").
@@ -298,10 +300,10 @@ func TestUpdateConfig(t *testing.T) {
 				makeTestSecret("worker1", "nowatch"),
 			},
 			remoteClients: map[string]*remoteClient{
-				"worker1": setReconnectState(newTestClient("nowatch", cancelCalled), 2),
+				"worker1": setReconnectState(newTestClient(t.Context(), "nowatch", cancelCalled), 2),
 			},
 			wantRemoteClients: map[string]*remoteClient{
-				"worker1": setReconnectState(newTestClient("nowatch", nil), 3),
+				"worker1": setReconnectState(newTestClient(t.Context(), "nowatch", nil), 3),
 			},
 			wantClusters: []kueue.MultiKueueCluster{
 				*utiltesting.MakeMultiKueueCluster("worker1").
@@ -326,10 +328,10 @@ func TestUpdateConfig(t *testing.T) {
 				makeTestSecret("worker1", "good config"),
 			},
 			remoteClients: map[string]*remoteClient{
-				"worker1": setReconnectState(newTestClient("nowatch", cancelCalled), 5),
+				"worker1": setReconnectState(newTestClient(t.Context(), "nowatch", cancelCalled), 5),
 			},
 			wantRemoteClients: map[string]*remoteClient{
-				"worker1": newTestClient("good config", nil),
+				"worker1": newTestClient(t.Context(), "good config", nil),
 			},
 			wantClusters: []kueue.MultiKueueCluster{
 				*utiltesting.MakeMultiKueueCluster("worker1").
@@ -353,10 +355,10 @@ func TestUpdateConfig(t *testing.T) {
 				makeTestSecret("worker1", "invalid"),
 			},
 			remoteClients: map[string]*remoteClient{
-				"worker1": setReconnectState(newTestClient("nowatch", cancelCalled), 5),
+				"worker1": setReconnectState(newTestClient(t.Context(), "nowatch", cancelCalled), 5),
 			},
 			wantRemoteClients: map[string]*remoteClient{
-				"worker1": newTestClient("invalid", nil),
+				"worker1": newTestClient(t.Context(), "invalid", nil),
 			},
 			wantClusters: []kueue.MultiKueueCluster{
 				*utiltesting.MakeMultiKueueCluster("worker1").
@@ -371,7 +373,7 @@ func TestUpdateConfig(t *testing.T) {
 
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
-			builder, ctx := getClientBuilder()
+			builder := getClientBuilder(t.Context())
 			builder = builder.WithLists(&kueue.MultiKueueClusterList{Items: tc.clusters})
 			builder = builder.WithLists(&corev1.SecretList{Items: tc.secrets})
 			builder = builder.WithStatusSubresource(slices.Map(tc.clusters, func(c *kueue.MultiKueueCluster) client.Object { return c })...)
@@ -380,15 +382,15 @@ func TestUpdateConfig(t *testing.T) {
 			adapters, _ := jobframework.GetMultiKueueAdapters(sets.New("batch/job"))
 			reconciler := newClustersReconciler(c, TestNamespace, 0, defaultOrigin, nil, adapters)
 
-			reconciler.rootContext = ctx
+			reconciler.rootContext = t.Context()
 
 			if len(tc.remoteClients) > 0 {
 				reconciler.remoteClients = tc.remoteClients
 			}
-			reconciler.builderOverride = fakeClientBuilder
+			reconciler.builderOverride = fakeClientBuilder(t.Context())
 
 			cancelCalledCount = 0
-			res, gotErr := reconciler.Reconcile(ctx, reconcile.Request{NamespacedName: types.NamespacedName{Name: tc.reconcileFor}})
+			res, gotErr := reconciler.Reconcile(t.Context(), reconcile.Request{NamespacedName: types.NamespacedName{Name: tc.reconcileFor}})
 			if gotErr != nil {
 				t.Errorf("unexpected reconcile error: %s", gotErr)
 			}
@@ -402,7 +404,7 @@ func TestUpdateConfig(t *testing.T) {
 			}
 
 			lst := &kueue.MultiKueueClusterList{}
-			gotErr = c.List(ctx, lst)
+			gotErr = c.List(t.Context(), lst)
 			if gotErr != nil {
 				t.Errorf("unexpected list clusters error: %s", gotErr)
 			}
@@ -530,11 +532,11 @@ func TestRemoteClientGC(t *testing.T) {
 
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
-			manageBuilder, ctx := getClientBuilder()
+			manageBuilder := getClientBuilder(t.Context())
 			manageBuilder = manageBuilder.WithLists(&kueue.WorkloadList{Items: tc.managersWorkloads}, &batchv1.JobList{Items: tc.managersJobs})
 			managerClient := manageBuilder.Build()
 
-			worker1Builder, _ := getClientBuilder()
+			worker1Builder := getClientBuilder(t.Context())
 			worker1Builder = worker1Builder.WithLists(&kueue.WorkloadList{Items: tc.workersWorkloads}, &batchv1.JobList{Items: tc.workersJobs})
 			worker1Client := worker1Builder.Build()
 
@@ -543,10 +545,10 @@ func TestRemoteClientGC(t *testing.T) {
 			w1remoteClient.client = worker1Client
 			w1remoteClient.connecting.Store(false)
 
-			w1remoteClient.runGC(ctx)
+			w1remoteClient.runGC(t.Context())
 
 			gotWorker1Workloads := &kueue.WorkloadList{}
-			err := worker1Client.List(ctx, gotWorker1Workloads)
+			err := worker1Client.List(t.Context(), gotWorker1Workloads)
 			if err != nil {
 				t.Error("unexpected list worker's workloads error")
 			}
@@ -556,7 +558,7 @@ func TestRemoteClientGC(t *testing.T) {
 			}
 
 			gotWorker1Job := &batchv1.JobList{}
-			err = worker1Client.List(ctx, gotWorker1Job)
+			err = worker1Client.List(t.Context(), gotWorker1Job)
 			if err != nil {
 				t.Error("unexpected list worker's jobs error")
 			}
diff --git a/pkg/controller/admissionchecks/multikueue/workload_test.go b/pkg/controller/admissionchecks/multikueue/workload_test.go
index d896db867..38569941f 100644
--- a/pkg/controller/admissionchecks/multikueue/workload_test.go
+++ b/pkg/controller/admissionchecks/multikueue/workload_test.go
@@ -1003,7 +1003,7 @@ func TestWlReconcile(t *testing.T) {
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
 			features.SetFeatureGateDuringTest(t, features.MultiKueueBatchJobWithManagedBy, !tc.withoutJobManagedBy)
-			managerBuilder, ctx := getClientBuilder()
+			managerBuilder := getClientBuilder(t.Context())
 			managerBuilder = managerBuilder.WithInterceptorFuncs(interceptor.Funcs{SubResourcePatch: utiltesting.TreatSSAAsStrategicMerge})
 
 			workerClusters := []string{"worker1"}
@@ -1024,7 +1024,7 @@ func TestWlReconcile(t *testing.T) {
 			adapters, _ := jobframework.GetMultiKueueAdapters(sets.New("batch/job"))
 			cRec := newClustersReconciler(managerClient, TestNamespace, 0, defaultOrigin, nil, adapters)
 
-			worker1Builder, _ := getClientBuilder()
+			worker1Builder := getClientBuilder(t.Context())
 			worker1Builder = worker1Builder.WithLists(&kueue.WorkloadList{Items: tc.worker1Workloads}, &batchv1.JobList{Items: tc.worker1Jobs})
 			worker1Client := worker1Builder.Build()
 
@@ -1035,7 +1035,7 @@ func TestWlReconcile(t *testing.T) {
 
 			var worker2Client client.WithWatch
 			if tc.useSecondWorker {
-				worker2Builder, _ := getClientBuilder()
+				worker2Builder := getClientBuilder(t.Context())
 				worker2Builder = worker2Builder.WithLists(&kueue.WorkloadList{Items: tc.worker2Workloads}, &batchv1.JobList{Items: tc.worker2Jobs})
 				worker2Builder = worker2Builder.WithInterceptorFuncs(interceptor.Funcs{
 					Get: func(ctx context.Context, c client.WithWatch, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
@@ -1076,13 +1076,13 @@ func TestWlReconcile(t *testing.T) {
 				})
 			}
 
-			_, gotErr := reconciler.Reconcile(ctx, reconcile.Request{NamespacedName: types.NamespacedName{Name: tc.reconcileFor, Namespace: TestNamespace}})
+			_, gotErr := reconciler.Reconcile(t.Context(), reconcile.Request{NamespacedName: types.NamespacedName{Name: tc.reconcileFor, Namespace: TestNamespace}})
 			if diff := cmp.Diff(tc.wantError, gotErr, cmpopts.EquateErrors()); diff != "" {
 				t.Errorf("unexpected error (-want/+got):\n%s", diff)
 			}
 
 			gotManagersWorkloads := &kueue.WorkloadList{}
-			if err := managerClient.List(ctx, gotManagersWorkloads); err != nil {
+			if err := managerClient.List(t.Context(), gotManagersWorkloads); err != nil {
 				t.Errorf("unexpected list manager's workloads error: %s", err)
 			} else {
 				if diff := cmp.Diff(tc.wantManagersWorkloads, gotManagersWorkloads.Items, objCheckOpts...); diff != "" {
@@ -1091,7 +1091,7 @@ func TestWlReconcile(t *testing.T) {
 			}
 
 			gotWorker1Workloads := &kueue.WorkloadList{}
-			if err := worker1Client.List(ctx, gotWorker1Workloads); err != nil {
+			if err := worker1Client.List(t.Context(), gotWorker1Workloads); err != nil {
 				t.Errorf("unexpected list worker's workloads error: %s", err)
 			} else {
 				if diff := cmp.Diff(tc.wantWorker1Workloads, gotWorker1Workloads.Items, objCheckOpts...); diff != "" {
@@ -1100,7 +1100,7 @@ func TestWlReconcile(t *testing.T) {
 			}
 
 			gotManagersJobs := &batchv1.JobList{}
-			if err := managerClient.List(ctx, gotManagersJobs); err != nil {
+			if err := managerClient.List(t.Context(), gotManagersJobs); err != nil {
 				t.Errorf("unexpected list manager's jobs error %s", err)
 			} else {
 				if diff := cmp.Diff(tc.wantManagersJobs, gotManagersJobs.Items, objCheckOpts...); diff != "" {
@@ -1109,7 +1109,7 @@ func TestWlReconcile(t *testing.T) {
 			}
 
 			gotWorker1Jobs := &batchv1.JobList{}
-			if err := worker1Client.List(ctx, gotWorker1Jobs); err != nil {
+			if err := worker1Client.List(t.Context(), gotWorker1Jobs); err != nil {
 				t.Error("unexpected list worker's jobs error")
 			} else {
 				if diff := cmp.Diff(tc.wantWorker1Jobs, gotWorker1Jobs.Items, objCheckOpts...); diff != "" {
@@ -1119,7 +1119,7 @@ func TestWlReconcile(t *testing.T) {
 
 			if tc.useSecondWorker {
 				gotWorker2Workloads := &kueue.WorkloadList{}
-				if err := worker2Client.List(ctx, gotWorker2Workloads); err != nil {
+				if err := worker2Client.List(t.Context(), gotWorker2Workloads); err != nil {
 					t.Errorf("unexpected list worker2 workloads error: %s", err)
 				} else {
 					if diff := cmp.Diff(tc.wantWorker2Workloads, gotWorker2Workloads.Items, objCheckOpts...); diff != "" {
@@ -1128,7 +1128,7 @@ func TestWlReconcile(t *testing.T) {
 				}
 
 				gotWorker2Jobs := &batchv1.JobList{}
-				if err := worker2Client.List(ctx, gotWorker2Jobs); err != nil {
+				if err := worker2Client.List(t.Context(), gotWorker2Jobs); err != nil {
 					t.Errorf("unexpected list worker2 jobs error: %s", err)
 				} else {
 					if diff := cmp.Diff(tc.wantWorker2Jobs, gotWorker2Jobs.Items, objCheckOpts...); diff != "" {
diff --git a/pkg/controller/admissionchecks/provisioning/admissioncheck_reconciler_test.go b/pkg/controller/admissionchecks/provisioning/admissioncheck_reconciler_test.go
index 09b94c573..80705fb55 100644
--- a/pkg/controller/admissionchecks/provisioning/admissioncheck_reconciler_test.go
+++ b/pkg/controller/admissionchecks/provisioning/admissioncheck_reconciler_test.go
@@ -114,7 +114,7 @@ func TestReconcileAdmissionCheck(t *testing.T) {
 
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
-			builder, ctx := getClientBuilder()
+			builder, ctx := getClientBuilder(t.Context())
 
 			builder = builder.WithObjects(tc.check)
 			builder = builder.WithStatusSubresource(tc.check)
diff --git a/pkg/controller/admissionchecks/provisioning/controller_test.go b/pkg/controller/admissionchecks/provisioning/controller_test.go
index 22ba38943..4cfa77155 100644
--- a/pkg/controller/admissionchecks/provisioning/controller_test.go
+++ b/pkg/controller/admissionchecks/provisioning/controller_test.go
@@ -1256,7 +1256,7 @@ func TestReconcile(t *testing.T) {
 				interceptorFuncs.Create = tc.interceptorFuncsCreate
 			}
 
-			builder, ctx := getClientBuilder()
+			builder, ctx := getClientBuilder(t.Context())
 			builder = builder.WithInterceptorFuncs(interceptorFuncs)
 			builder = builder.WithObjects(tc.workload)
 			builder = builder.WithStatusSubresource(tc.workload)
@@ -1441,7 +1441,7 @@ func TestActiveOrLastPRForChecks(t *testing.T) {
 				baseCheck.Name: baseConfig.DeepCopy(),
 			}
 
-			builder, ctx := getClientBuilder()
+			builder, ctx := getClientBuilder(t.Context())
 
 			builder = builder.WithObjects(workload)
 			builder = builder.WithStatusSubresource(workload)
diff --git a/pkg/controller/admissionchecks/provisioning/indexer_test.go b/pkg/controller/admissionchecks/provisioning/indexer_test.go
index 9b964b7c5..4f6eb2e22 100644
--- a/pkg/controller/admissionchecks/provisioning/indexer_test.go
+++ b/pkg/controller/admissionchecks/provisioning/indexer_test.go
@@ -39,13 +39,12 @@ const (
 	TestNamespace = "ns"
 )
 
-func getClientBuilder() (*fake.ClientBuilder, context.Context) {
+func getClientBuilder(ctx context.Context) (*fake.ClientBuilder, context.Context) {
 	scheme := runtime.NewScheme()
 	utilruntime.Must(clientgoscheme.AddToScheme(scheme))
 	utilruntime.Must(kueue.AddToScheme(scheme))
 	utilruntime.Must(autoscaling.AddToScheme(scheme))
 
-	ctx := context.Background()
 	builder := fake.NewClientBuilder().WithScheme(scheme).WithObjects(utiltesting.MakeNamespace(TestNamespace))
 	_ = SetupIndexer(ctx, utiltesting.AsIndexer(builder))
 	return builder, ctx
@@ -132,7 +131,7 @@ func TestIndexProvisioningRequests(t *testing.T) {
 	}
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
-			builder, ctx := getClientBuilder()
+			builder, ctx := getClientBuilder(t.Context())
 			k8sclient := builder.Build()
 			for _, req := range tc.requests {
 				if err := k8sclient.Create(ctx, req); err != nil {
@@ -242,7 +241,7 @@ func TestIndexWorkload(t *testing.T) {
 	}
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
-			builder, ctx := getClientBuilder()
+			builder, ctx := getClientBuilder(t.Context())
 			k8sclient := builder.Build()
 			for _, wl := range tc.workloads {
 				if err := k8sclient.Create(ctx, wl); err != nil {
@@ -338,7 +337,7 @@ func TestIndexAdmissionChecks(t *testing.T) {
 	}
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
-			builder, ctx := getClientBuilder()
+			builder, ctx := getClientBuilder(t.Context())
 			k8sclient := builder.Build()
 			for _, req := range tc.checks {
 				if err := k8sclient.Create(ctx, req); err != nil {
diff --git a/pkg/controller/core/clusterqueue_controller_test.go b/pkg/controller/core/clusterqueue_controller_test.go
index f6db2a06f..08f8836f9 100644
--- a/pkg/controller/core/clusterqueue_controller_test.go
+++ b/pkg/controller/core/clusterqueue_controller_test.go
@@ -568,7 +568,7 @@ func TestClusterQueuePendingWorkloadsStatus(t *testing.T) {
 				QueueingStrategy(kueue.StrictFIFO).Obj()
 			lq := utiltesting.MakeLocalQueue(lqName, "").
 				ClusterQueue(cqName).Obj()
-			ctx := context.Background()
+			ctx := t.Context()
 
 			cl := utiltesting.NewClientBuilder().WithLists(defaultWls).WithObjects(lq, cq).WithStatusSubresource(lq, cq).
 				Build()
diff --git a/pkg/controller/core/cohort_controller_test.go b/pkg/controller/core/cohort_controller_test.go
index ccaaf801e..9a0d6b89b 100644
--- a/pkg/controller/core/cohort_controller_test.go
+++ b/pkg/controller/core/cohort_controller_test.go
@@ -36,7 +36,7 @@ import (
 
 func TestCohortReconcileCohortNotFoundDelete(t *testing.T) {
 	cl := utiltesting.NewClientBuilder().Build()
-	ctx := context.Background()
+	ctx := t.Context()
 	cache := cache.New(cl)
 	qManager := queue.NewManager(cl, cache)
 	reconciler := NewCohortReconciler(cl, cache, qManager)
@@ -71,7 +71,7 @@ func TestCohortReconcileCohortNotFoundDelete(t *testing.T) {
 func TestCohortReconcileCohortNotFoundIdempotentDelete(t *testing.T) {
 	cl := utiltesting.NewClientBuilder().
 		Build()
-	ctx := context.Background()
+	ctx := t.Context()
 	cache := cache.New(cl)
 	qManager := queue.NewManager(cl, cache)
 	reconciler := NewCohortReconciler(cl, cache, qManager)
@@ -108,7 +108,7 @@ func TestCohortReconcileCycleNoError(t *testing.T) {
 		WithObjects(cohortA, cohortB).
 		WithStatusSubresource(&kueue.Cohort{}).
 		Build()
-	ctx := context.Background()
+	ctx := t.Context()
 	cache := cache.New(cl)
 	qManager := queue.NewManager(cl, cache)
 	reconciler := NewCohortReconciler(cl, cache, qManager)
@@ -146,7 +146,7 @@ func TestCohortReconcileCycleNoError(t *testing.T) {
 }
 
 func TestCohortReconcileErrorOtherThanNotFoundNotDeleted(t *testing.T) {
-	ctx := context.Background()
+	ctx := t.Context()
 	funcs := interceptor.Funcs{
 		Get: func(ctx context.Context, client client.WithWatch, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
 			return errors.New("error")
@@ -185,7 +185,7 @@ func TestCohortReconcileErrorOtherThanNotFoundNotDeleted(t *testing.T) {
 }
 
 func TestCohortReconcileLifecycle(t *testing.T) {
-	ctx := context.Background()
+	ctx := t.Context()
 	cohort := utiltesting.MakeCohort("cohort").ResourceGroup(
 		utiltesting.MakeFlavorQuotas("red").Resource("cpu", "10").FlavorQuotas,
 	).Obj()
diff --git a/pkg/controller/jobframework/base_webhook_test.go b/pkg/controller/jobframework/base_webhook_test.go
index 11a06ede7..d9f72e76c 100644
--- a/pkg/controller/jobframework/base_webhook_test.go
+++ b/pkg/controller/jobframework/base_webhook_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package jobframework_test
 
 import (
-	"context"
 	"testing"
 
 	"github.com/google/go-cmp/cmp"
@@ -289,7 +288,7 @@ func TestBaseWebhookDefault(t *testing.T) {
 				Queues:                     queueManager,
 				Cache:                      cqCache,
 			}
-			if err := w.Default(context.Background(), tc.job); err != nil {
+			if err := w.Default(t.Context(), tc.job); err != nil {
 				t.Errorf("set defaults by base webhook")
 			}
 			if diff := cmp.Diff(tc.want, tc.job); len(diff) != 0 {
@@ -350,7 +349,7 @@ func TestValidateOnCreate(t *testing.T) {
 			w := &jobframework.BaseWebhook{
 				FromObject: makeTestGenericJob().withValidateOnCreate(tc.validateOnCreate).fromObject,
 			}
-			gotWarn, gotErr := w.ValidateCreate(context.Background(), tc.job)
+			gotWarn, gotErr := w.ValidateCreate(t.Context(), tc.job)
 			if diff := cmp.Diff(tc.wantErr, gotErr); diff != "" {
 				t.Errorf("validate create err mismatch (-want +got):\n%s", diff)
 			}
@@ -427,7 +426,7 @@ func TestValidateOnUpdate(t *testing.T) {
 			w := &jobframework.BaseWebhook{
 				FromObject: makeTestGenericJob().withValidateOnUpdate(tc.validateOnUpdate).fromObject,
 			}
-			gotWarn, gotErr := w.ValidateUpdate(context.Background(), tc.oldJob, tc.job)
+			gotWarn, gotErr := w.ValidateUpdate(t.Context(), tc.oldJob, tc.job)
 			if diff := cmp.Diff(tc.wantErr, gotErr); diff != "" {
 				t.Errorf("validate create err mismatch (-want +got):\n%s", diff)
 			}
diff --git a/pkg/controller/jobframework/setup_test.go b/pkg/controller/jobframework/setup_test.go
index 9ae85bca1..07aeb9dce 100644
--- a/pkg/controller/jobframework/setup_test.go
+++ b/pkg/controller/jobframework/setup_test.go
@@ -259,7 +259,7 @@ func TestSetupIndexes(t *testing.T) {
 	}
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
-			ctx, cancel := context.WithCancel(context.Background())
+			ctx, cancel := context.WithCancel(t.Context())
 			defer cancel()
 
 			builder := utiltesting.NewClientBuilder().WithObjects(utiltesting.MakeNamespace(testNamespace))
diff --git a/pkg/controller/jobframework/webhook/defaulter_test.go b/pkg/controller/jobframework/webhook/defaulter_test.go
index 1f2c085aa..06db51f37 100644
--- a/pkg/controller/jobframework/webhook/defaulter_test.go
+++ b/pkg/controller/jobframework/webhook/defaulter_test.go
@@ -82,7 +82,7 @@ func TestLossLessDefaulter(t *testing.T) {
 			},
 		},
 	}
-	resp := handler.Handle(context.Background(), req)
+	resp := handler.Handle(t.Context(), req)
 	if !resp.Allowed {
 		t.Errorf("Response not allowed")
 	}
diff --git a/pkg/controller/jobs/jobset/jobset_webhook_test.go b/pkg/controller/jobs/jobset/jobset_webhook_test.go
index 1d2c2fbee..f79821126 100644
--- a/pkg/controller/jobs/jobset/jobset_webhook_test.go
+++ b/pkg/controller/jobs/jobset/jobset_webhook_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package jobset
 
 import (
-	"context"
 	"testing"
 
 	"github.com/google/go-cmp/cmp"
@@ -105,7 +104,7 @@ func TestValidateCreate(t *testing.T) {
 	for _, tc := range testcases {
 		t.Run(tc.name, func(t *testing.T) {
 			jsw := &JobSetWebhook{}
-			_, gotErr := jsw.ValidateCreate(context.Background(), tc.job)
+			_, gotErr := jsw.ValidateCreate(t.Context(), tc.job)
 
 			if diff := cmp.Diff(tc.wantErr, gotErr); diff != "" {
 				t.Errorf("validateCreate() mismatch (-want +got):\n%s", diff)
diff --git a/pkg/controller/jobs/leaderworkerset/leaderworkerset_webhook_test.go b/pkg/controller/jobs/leaderworkerset/leaderworkerset_webhook_test.go
index 2b957e7a6..42bc3ebbc 100644
--- a/pkg/controller/jobs/leaderworkerset/leaderworkerset_webhook_test.go
+++ b/pkg/controller/jobs/leaderworkerset/leaderworkerset_webhook_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package leaderworkerset
 
 import (
-	"context"
 	"testing"
 
 	"github.com/google/go-cmp/cmp"
@@ -660,7 +659,7 @@ func TestValidateUpdate(t *testing.T) {
 				jobframework.EnableIntegrationsForTest(t, integration)
 			}
 
-			ctx := context.Background()
+			ctx := t.Context()
 
 			wh := &Webhook{}
 
diff --git a/pkg/controller/jobs/mpijob/mpijob_webhook_test.go b/pkg/controller/jobs/mpijob/mpijob_webhook_test.go
index ce8afbdfd..5a817f9d7 100644
--- a/pkg/controller/jobs/mpijob/mpijob_webhook_test.go
+++ b/pkg/controller/jobs/mpijob/mpijob_webhook_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package mpijob
 
 import (
-	"context"
 	"testing"
 
 	"github.com/google/go-cmp/cmp"
@@ -123,7 +122,7 @@ func TestValidateCreate(t *testing.T) {
 	for _, tc := range testcases {
 		t.Run(tc.name, func(t *testing.T) {
 			jsw := &MpiJobWebhook{}
-			_, gotErr := jsw.ValidateCreate(context.Background(), tc.job)
+			_, gotErr := jsw.ValidateCreate(t.Context(), tc.job)
 
 			if diff := cmp.Diff(tc.wantErr, gotErr); diff != "" {
 				t.Errorf("validateCreate() mismatch (-want +got):\n%s", diff)
diff --git a/pkg/controller/jobs/raycluster/raycluster_webhook_test.go b/pkg/controller/jobs/raycluster/raycluster_webhook_test.go
index c6f4eda22..3303ac8b9 100644
--- a/pkg/controller/jobs/raycluster/raycluster_webhook_test.go
+++ b/pkg/controller/jobs/raycluster/raycluster_webhook_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package raycluster
 
 import (
-	"context"
 	"fmt"
 	"testing"
 
@@ -125,7 +124,7 @@ func TestValidateDefault(t *testing.T) {
 				cache:                      cqCache,
 			}
 			result := tc.oldJob.DeepCopy()
-			if err := wh.Default(context.Background(), result); err != nil {
+			if err := wh.Default(t.Context(), result); err != nil {
 				t.Errorf("unexpected Default() error: %s", err)
 			}
 			if diff := cmp.Diff(tc.newJob, result); diff != "" {
@@ -257,7 +256,7 @@ func TestValidateCreate(t *testing.T) {
 			wh := &RayClusterWebhook{
 				manageJobsWithoutQueueName: tc.manageAll,
 			}
-			_, result := wh.ValidateCreate(context.Background(), tc.job)
+			_, result := wh.ValidateCreate(t.Context(), tc.job)
 			if diff := cmp.Diff(tc.wantErr, result); diff != "" {
 				t.Errorf("ValidateCreate() mismatch (-want +got):\n%s", diff)
 			}
@@ -323,7 +322,7 @@ func TestValidateUpdate(t *testing.T) {
 			wh := &RayClusterWebhook{
 				manageJobsWithoutQueueName: tc.manageAll,
 			}
-			_, result := wh.ValidateUpdate(context.Background(), tc.oldJob, tc.newJob)
+			_, result := wh.ValidateUpdate(t.Context(), tc.oldJob, tc.newJob)
 			if diff := cmp.Diff(tc.wantErr, result); diff != "" {
 				t.Errorf("ValidateUpdate() mismatch (-want +got):\n%s", diff)
 			}
diff --git a/pkg/controller/jobs/rayjob/rayjob_webhook_test.go b/pkg/controller/jobs/rayjob/rayjob_webhook_test.go
index d95588642..879fd1b61 100644
--- a/pkg/controller/jobs/rayjob/rayjob_webhook_test.go
+++ b/pkg/controller/jobs/rayjob/rayjob_webhook_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package rayjob
 
 import (
-	"context"
 	"fmt"
 	"testing"
 
@@ -124,7 +123,7 @@ func TestValidateDefault(t *testing.T) {
 				cache:                      cqCache,
 			}
 			result := tc.oldJob.DeepCopy()
-			if err := wh.Default(context.Background(), result); err != nil {
+			if err := wh.Default(t.Context(), result); err != nil {
 				t.Errorf("unexpected Default() error: %s", err)
 			}
 			if diff := cmp.Diff(tc.newJob, result); diff != "" {
@@ -284,7 +283,7 @@ func TestValidateCreate(t *testing.T) {
 			wh := &RayJobWebhook{
 				manageJobsWithoutQueueName: tc.manageAll,
 			}
-			_, result := wh.ValidateCreate(context.Background(), tc.job)
+			_, result := wh.ValidateCreate(t.Context(), tc.job)
 			if diff := cmp.Diff(tc.wantErr, result); diff != "" {
 				t.Errorf("ValidateCreate() mismatch (-want +got):\n%s", diff)
 			}
@@ -381,7 +380,7 @@ func TestValidateUpdate(t *testing.T) {
 			wh := &RayJobWebhook{
 				manageJobsWithoutQueueName: tc.manageAll,
 			}
-			_, result := wh.ValidateUpdate(context.Background(), tc.oldJob, tc.newJob)
+			_, result := wh.ValidateUpdate(t.Context(), tc.oldJob, tc.newJob)
 			if diff := cmp.Diff(tc.wantErr, result); diff != "" {
 				t.Errorf("ValidateUpdate() mismatch (-want +got):\n%s", diff)
 			}
diff --git a/pkg/controller/jobs/statefulset/statefulset_webhook_test.go b/pkg/controller/jobs/statefulset/statefulset_webhook_test.go
index 1e61fe688..55930510b 100644
--- a/pkg/controller/jobs/statefulset/statefulset_webhook_test.go
+++ b/pkg/controller/jobs/statefulset/statefulset_webhook_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package statefulset
 
 import (
-	"context"
 	"testing"
 
 	"github.com/google/go-cmp/cmp"
@@ -611,7 +610,7 @@ func TestValidateUpdate(t *testing.T) {
 	for name, tc := range testCases {
 		t.Run(name, func(t *testing.T) {
 			t.Cleanup(jobframework.EnableIntegrationsForTest(t, tc.integrations...))
-			ctx := context.Background()
+			ctx := t.Context()
 
 			wh := &Webhook{}
 
diff --git a/pkg/queue/cluster_queue_test.go b/pkg/queue/cluster_queue_test.go
index af0702264..23e6f268b 100644
--- a/pkg/queue/cluster_queue_test.go
+++ b/pkg/queue/cluster_queue_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package queue
 
 import (
-	"context"
 	"testing"
 	"time"
 
@@ -443,7 +442,7 @@ func TestClusterQueueImpl(t *testing.T) {
 
 			if test.queueInadmissibleWorkloads {
 				if diff := cmp.Diff(test.wantInadmissibleWorkloadsRequeued,
-					cq.QueueInadmissibleWorkloads(context.Background(), cl)); diff != "" {
+					cq.QueueInadmissibleWorkloads(t.Context(), cl)); diff != "" {
 					t.Errorf("Unexpected requeuing of inadmissible workloads (-want,+got):\n%s", diff)
 				}
 			}
@@ -464,7 +463,7 @@ func TestQueueInadmissibleWorkloadsDuringScheduling(t *testing.T) {
 	cq.namespaceSelector = labels.Everything()
 	wl := utiltesting.MakeWorkload("workload-1", defaultNamespace).Obj()
 	cl := utiltesting.NewFakeClient(wl, utiltesting.MakeNamespace(defaultNamespace))
-	ctx := context.Background()
+	ctx := t.Context()
 	cq.PushOrUpdate(workload.NewInfo(wl))
 
 	wantActiveWorkloads := []string{workload.Key(wl)}
diff --git a/pkg/queue/manager_test.go b/pkg/queue/manager_test.go
index 5bc256c56..8a7ed1cb2 100644
--- a/pkg/queue/manager_test.go
+++ b/pkg/queue/manager_test.go
@@ -57,7 +57,7 @@ func TestAddLocalQueueOrphans(t *testing.T) {
 	)
 	manager := NewManager(kClient, nil)
 	q := utiltesting.MakeLocalQueue("foo", "earth").Obj()
-	if err := manager.AddLocalQueue(context.Background(), q); err != nil {
+	if err := manager.AddLocalQueue(t.Context(), q); err != nil {
 		t.Fatalf("Failed adding queue: %v", err)
 	}
 	qImpl := manager.localQueues[Key(q)]
@@ -88,7 +88,7 @@ func TestAddClusterQueueOrphans(t *testing.T) {
 		queues[0],
 		queues[1],
 	)
-	ctx := context.Background()
+	ctx := t.Context()
 	manager := NewManager(kClient, nil)
 	cq := utiltesting.MakeClusterQueue("cq").Obj()
 	if err := manager.AddClusterQueue(ctx, cq); err != nil {
@@ -141,7 +141,7 @@ func TestUpdateClusterQueue(t *testing.T) {
 		utiltesting.MakeWorkload("b", defaultNamespace).Queue("bar").Creation(now).Obj(),
 	}
 	// Setup.
-	ctx := context.Background()
+	ctx := t.Context()
 	cl := utiltesting.NewFakeClient(utiltesting.MakeNamespace(defaultNamespace))
 	manager := NewManager(cl, nil)
 	for _, cq := range clusterQueues {
@@ -223,7 +223,7 @@ func TestRequeueWorkloadsCohortCycle(t *testing.T) {
 	lq := utiltesting.MakeLocalQueue("foo", defaultNamespace).ClusterQueue("cq1").Obj()
 	wl := utiltesting.MakeWorkload("a", defaultNamespace).Queue("foo").Creation(time.Now()).Obj()
 	// Setup.
-	ctx := context.Background()
+	ctx := t.Context()
 	cl := utiltesting.NewFakeClient(utiltesting.MakeNamespace(defaultNamespace))
 	manager := NewManager(cl, nil)
 	for _, cohort := range cohorts {
@@ -254,7 +254,7 @@ func TestRequeueWorkloadsCohortCycle(t *testing.T) {
 func TestClusterQueueToActive(t *testing.T) {
 	stoppedCq := utiltesting.MakeClusterQueue("cq1").Cohort("alpha").Condition(kueue.ClusterQueueActive, metav1.ConditionFalse, "ByTest", "by test").Obj()
 	runningCq := utiltesting.MakeClusterQueue("cq1").Cohort("alpha").Condition(kueue.ClusterQueueActive, metav1.ConditionTrue, "ByTest", "by test").Obj()
-	ctx := context.Background()
+	ctx := t.Context()
 	cl := utiltesting.NewFakeClient(utiltesting.MakeNamespace(defaultNamespace))
 	manager := NewManager(cl, nil)
 
@@ -326,7 +326,7 @@ func TestUpdateLocalQueue(t *testing.T) {
 	if err := kueue.AddToScheme(scheme); err != nil {
 		t.Fatalf("Failed adding kueue scheme: %s", err)
 	}
-	ctx := context.Background()
+	ctx := t.Context()
 	manager := NewManager(utiltesting.NewFakeClient(), nil)
 	for _, cq := range clusterQueues {
 		if err := manager.AddClusterQueue(ctx, cq); err != nil {
@@ -371,7 +371,7 @@ func TestDeleteLocalQueue(t *testing.T) {
 	q := utiltesting.MakeLocalQueue("foo", "").ClusterQueue("cq").Obj()
 	wl := utiltesting.MakeWorkload("a", "").Queue("foo").Obj()
 
-	ctx := context.Background()
+	ctx := t.Context()
 	cl := utiltesting.NewFakeClient(wl)
 	manager := NewManager(cl, nil)
 
@@ -399,7 +399,7 @@ func TestDeleteLocalQueue(t *testing.T) {
 func TestAddWorkload(t *testing.T) {
 	manager := NewManager(utiltesting.NewFakeClient(), nil)
 	cq := utiltesting.MakeClusterQueue("cq").Obj()
-	if err := manager.AddClusterQueue(context.Background(), cq); err != nil {
+	if err := manager.AddClusterQueue(t.Context(), cq); err != nil {
 		t.Fatalf("Failed adding clusterQueue %s: %v", cq.Name, err)
 	}
 	queues := []*kueue.LocalQueue{
@@ -407,7 +407,7 @@ func TestAddWorkload(t *testing.T) {
 		utiltesting.MakeLocalQueue("bar", "mars").Obj(),
 	}
 	for _, q := range queues {
-		if err := manager.AddLocalQueue(context.Background(), q); err != nil {
+		if err := manager.AddLocalQueue(t.Context(), q); err != nil {
 			t.Fatalf("Failed adding queue %s: %v", q.Name, err)
 		}
 	}
@@ -466,7 +466,7 @@ func TestAddWorkload(t *testing.T) {
 }
 
 func TestStatus(t *testing.T) {
-	ctx := context.Background()
+	ctx := t.Context()
 	scheme := runtime.NewScheme()
 	if err := kueue.AddToScheme(scheme); err != nil {
 		t.Fatalf("Failed adding kueue scheme: %s", err)
@@ -632,7 +632,7 @@ func TestRequeueWorkloadStrictFIFO(t *testing.T) {
 		t.Run(tc.workload.Name, func(t *testing.T) {
 			cl := utiltesting.NewFakeClient()
 			manager := NewManager(cl, nil)
-			ctx := context.Background()
+			ctx := t.Context()
 			if err := manager.AddClusterQueue(ctx, cq); err != nil {
 				t.Fatalf("Failed adding cluster queue %s: %v", cq.Name, err)
 			}
@@ -791,7 +791,7 @@ func TestUpdateWorkload(t *testing.T) {
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
 			manager := NewManager(utiltesting.NewFakeClient(), nil)
-			ctx := context.Background()
+			ctx := t.Context()
 			for _, cq := range tc.clusterQueues {
 				if err := manager.AddClusterQueue(ctx, cq); err != nil {
 					t.Fatalf("Adding cluster queue %s: %v", cq.Name, err)
@@ -904,7 +904,7 @@ func TestHeads(t *testing.T) {
 	}
 	for _, tc := range tests {
 		t.Run(tc.name, func(t *testing.T) {
-			ctx, cancel := context.WithTimeout(context.Background(), headsTimeout)
+			ctx, cancel := context.WithTimeout(t.Context(), headsTimeout)
 			defer cancel()
 			fakeC := &fakeStatusChecker{}
 			manager := NewManager(utiltesting.NewFakeClient(), fakeC)
@@ -1145,7 +1145,7 @@ func TestHeadsAsync(t *testing.T) {
 	}
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
-			ctx, cancel := context.WithTimeout(context.Background(), headsTimeout)
+			ctx, cancel := context.WithTimeout(t.Context(), headsTimeout)
 			defer cancel()
 			client := utiltesting.NewFakeClient(tc.initialObjs...)
 			manager := NewManager(client, nil)
@@ -1162,7 +1162,7 @@ func TestHeadsAsync(t *testing.T) {
 // TestHeadsCancelled ensures that the Heads call returns when the context is closed.
 func TestHeadsCancelled(t *testing.T) {
 	manager := NewManager(utiltesting.NewFakeClient(), nil)
-	ctx, cancel := context.WithCancel(context.Background())
+	ctx, cancel := context.WithCancel(t.Context())
 	go func() {
 		cancel()
 	}()
@@ -1217,7 +1217,7 @@ func TestGetPendingWorkloadsInfo(t *testing.T) {
 	if err := kueue.AddToScheme(scheme); err != nil {
 		t.Fatalf("Failed adding kueue scheme: %s", err)
 	}
-	ctx := context.Background()
+	ctx := t.Context()
 	manager := NewManager(utiltesting.NewFakeClient(), nil)
 	for _, cq := range clusterQueues {
 		if err := manager.AddClusterQueue(ctx, cq); err != nil {
diff --git a/pkg/scheduler/scheduler_test.go b/pkg/scheduler/scheduler_test.go
index a8d78d8fb..a004b7e6e 100644
--- a/pkg/scheduler/scheduler_test.go
+++ b/pkg/scheduler/scheduler_test.go
@@ -3359,7 +3359,7 @@ func TestEntryOrdering(t *testing.T) {
 	} {
 		t.Run(tc.name, func(t *testing.T) {
 			features.SetFeatureGateDuringTest(t, features.PrioritySortingWithinCohort, tc.prioritySorting)
-			iter := makeIterator(context.Background(), tc.input, tc.workloadOrdering, false)
+			iter := makeIterator(t.Context(), tc.input, tc.workloadOrdering, false)
 			order := make([]string, len(tc.input))
 			for i := range tc.input {
 				order[i] = iter.pop().Obj.Name
diff --git a/pkg/util/admissioncheck/admissioncheck_test.go b/pkg/util/admissioncheck/admissioncheck_test.go
index b86ab5947..aa83128c2 100644
--- a/pkg/util/admissioncheck/admissioncheck_test.go
+++ b/pkg/util/admissioncheck/admissioncheck_test.go
@@ -104,7 +104,7 @@ func TestConfigHelper(t *testing.T) {
 				builder = builder.WithObjects(tc.config)
 			}
 			client := builder.Build()
-			ctx, cancel := context.WithCancel(context.Background())
+			ctx, cancel := context.WithCancel(t.Context())
 			defer cancel()
 
 			helper, err := NewConfigHelper[*kueue.ProvisioningRequestConfig](client)
@@ -208,7 +208,7 @@ func TestFilterCheckStates(t *testing.T) {
 				builder = builder.WithLists(&kueue.AdmissionCheckList{Items: tc.admissionchecks})
 			}
 			client := builder.Build()
-			ctx, cancel := context.WithCancel(context.Background())
+			ctx, cancel := context.WithCancel(t.Context())
 			defer cancel()
 
 			gotResult, _ := FilterForController(ctx, client, tc.states, "test-controller")
diff --git a/pkg/util/parallelize/parallelize_test.go b/pkg/util/parallelize/parallelize_test.go
index f21cf504e..4eb891053 100644
--- a/pkg/util/parallelize/parallelize_test.go
+++ b/pkg/util/parallelize/parallelize_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package parallelize
 
 import (
-	"context"
 	"errors"
 	"testing"
 
@@ -54,7 +53,7 @@ func TestUntil(t *testing.T) {
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
 			result = make([]int, 5)
-			err := Until(context.Background(), len(result), tc.op)
+			err := Until(t.Context(), len(result), tc.op)
 			if !errors.Is(err, tc.wantErr) {
 				t.Errorf("Got error %q, want %q", err, tc.wantErr)
 			}
diff --git a/pkg/util/priority/priority_test.go b/pkg/util/priority/priority_test.go
index 060d27d5b..624f64861 100644
--- a/pkg/util/priority/priority_test.go
+++ b/pkg/util/priority/priority_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package priority
 
 import (
-	"context"
 	"testing"
 
 	"github.com/google/go-cmp/cmp"
@@ -141,7 +140,7 @@ func TestGetPriorityFromPriorityClass(t *testing.T) {
 			builder := fake.NewClientBuilder().WithScheme(scheme).WithLists(tt.priorityClassList)
 			client := builder.Build()
 
-			name, source, value, err := GetPriorityFromPriorityClass(context.Background(), client, tt.priorityClassName)
+			name, source, value, err := GetPriorityFromPriorityClass(t.Context(), client, tt.priorityClassName)
 			if diff := cmp.Diff(tt.wantErr, err); diff != "" {
 				t.Errorf("unexpected error (-want,+got):\n%s", diff)
 			}
@@ -205,7 +204,7 @@ func TestGetPriorityFromWorkloadPriorityClass(t *testing.T) {
 			builder := fake.NewClientBuilder().WithScheme(scheme).WithLists(tt.workloadPriorityClassList)
 			client := builder.Build()
 
-			name, source, value, err := GetPriorityFromWorkloadPriorityClass(context.Background(), client, tt.workloadPriorityClassName)
+			name, source, value, err := GetPriorityFromWorkloadPriorityClass(t.Context(), client, tt.workloadPriorityClassName)
 			if diff := cmp.Diff(tt.wantErr, err); diff != "" {
 				t.Errorf("unexpected error (-want,+got):\n%s", diff)
 			}
diff --git a/pkg/util/routine/error_channel_test.go b/pkg/util/routine/error_channel_test.go
index 6fac1aa11..c50c7564b 100644
--- a/pkg/util/routine/error_channel_test.go
+++ b/pkg/util/routine/error_channel_test.go
@@ -35,7 +35,7 @@ func TestErrorChannel(t *testing.T) {
 		t.Errorf("expect %v from err channel, but got %v", err, actualErr)
 	}
 
-	ctx, cancel := context.WithCancel(context.Background())
+	ctx, cancel := context.WithCancel(t.Context())
 	errCh.SendErrorWithCancel(err, cancel)
 	if actualErr := errCh.ReceiveError(); !errors.Is(actualErr, err) {
 		t.Errorf("expect %v from err channel, but got %v", err, actualErr)
diff --git a/pkg/util/testing/context.go b/pkg/util/testing/context.go
index d8c7d2c0f..8a8a12568 100644
--- a/pkg/util/testing/context.go
+++ b/pkg/util/testing/context.go
@@ -29,5 +29,5 @@ func ContextWithLog(t *testing.T) (context.Context, logr.Logger) {
 	logger := testr.NewWithOptions(t, testr.Options{
 		Verbosity: 2,
 	})
-	return ctrl.LoggerInto(context.Background(), logger), logger
+	return ctrl.LoggerInto(t.Context(), logger), logger
 }
diff --git a/pkg/util/wait/backoff_test.go b/pkg/util/wait/backoff_test.go
index 88a8a07cd..1be6fe99c 100644
--- a/pkg/util/wait/backoff_test.go
+++ b/pkg/util/wait/backoff_test.go
@@ -88,7 +88,7 @@ func TestUntilWithBackoff(t *testing.T) {
 	for _, testCase := range testCases {
 		t.Run(testCase.name, func(t *testing.T) {
 			timer := makeSpyTimer()
-			ctx, cancel := context.WithCancel(context.Background())
+			ctx, cancel := context.WithCancel(t.Context())
 			defer cancel()
 
 			i := 0
diff --git a/pkg/visibility/api/v1beta1/pending_workloads_cq_test.go b/pkg/visibility/api/v1beta1/pending_workloads_cq_test.go
index 12e62fbdc..b515e7767 100644
--- a/pkg/visibility/api/v1beta1/pending_workloads_cq_test.go
+++ b/pkg/visibility/api/v1beta1/pending_workloads_cq_test.go
@@ -322,7 +322,7 @@ func TestPendingWorkloadsInCQ(t *testing.T) {
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
 			manager := queue.NewManager(utiltesting.NewFakeClient(), nil)
-			ctx, cancel := context.WithCancel(context.Background())
+			ctx, cancel := context.WithCancel(t.Context())
 			defer cancel()
 			go manager.CleanUpOnContext(ctx)
 			pendingWorkloadsInCqRest := NewPendingWorkloadsInCqREST(manager)
diff --git a/pkg/visibility/api/v1beta1/pending_workloads_lq_test.go b/pkg/visibility/api/v1beta1/pending_workloads_lq_test.go
index 5adf02dcd..fcd1e1fc0 100644
--- a/pkg/visibility/api/v1beta1/pending_workloads_lq_test.go
+++ b/pkg/visibility/api/v1beta1/pending_workloads_lq_test.go
@@ -439,7 +439,7 @@ func TestPendingWorkloadsInLQ(t *testing.T) {
 	for name, tc := range cases {
 		t.Run(name, func(t *testing.T) {
 			manager := queue.NewManager(utiltesting.NewFakeClient(), nil)
-			ctx, cancel := context.WithCancel(context.Background())
+			ctx, cancel := context.WithCancel(t.Context())
 			defer cancel()
 			go manager.CleanUpOnContext(ctx)
 			pendingWorkloadsInLqRest := NewPendingWorkloadsInLqREST(manager)
diff --git a/pkg/workload/workload_test.go b/pkg/workload/workload_test.go
index d3e1c226f..b9684d898 100644
--- a/pkg/workload/workload_test.go
+++ b/pkg/workload/workload_test.go
@@ -17,7 +17,6 @@ limitations under the License.
 package workload
 
 import (
-	"context"
 	"testing"
 	"time"
 
@@ -423,7 +422,7 @@ func TestUpdateWorkloadStatus(t *testing.T) {
 			workload := utiltesting.MakeWorkload("foo", "bar").Generation(1).Obj()
 			workload.Status = tc.oldStatus
 			cl := utiltesting.NewFakeClientSSAAsSM(workload)
-			ctx := context.Background()
+			ctx := t.Context()
 			err := UpdateStatus(ctx, cl, workload, tc.condType, tc.condStatus, tc.reason, tc.message, "manager-prefix", fakeClock)
 			if err != nil {
 				t.Fatalf("Failed updating status: %v", err)
diff --git a/test/e2e/certmanager/suite_test.go b/test/e2e/certmanager/suite_test.go
index 4941e4411..87b023ccc 100644
--- a/test/e2e/certmanager/suite_test.go
+++ b/test/e2e/certmanager/suite_test.go
@@ -25,7 +25,6 @@ import (
 
 	"github.com/onsi/ginkgo/v2"
 	"github.com/onsi/gomega"
-	ctrl "sigs.k8s.io/controller-runtime"
 	"sigs.k8s.io/controller-runtime/pkg/client"
 
 	"sigs.k8s.io/kueue/apis/config/v1beta1"
@@ -50,10 +49,10 @@ func TestAPIs(t *testing.T) {
 }
 
 var _ = ginkgo.BeforeSuite(func() {
-	ctrl.SetLogger(util.NewTestingLogger(ginkgo.GinkgoWriter, -3))
+	util.SetupLogger()
 
 	k8sClient, _ = util.CreateClientUsingCluster("")
-	ctx = context.Background()
+	ctx = ginkgo.GinkgoT().Context()
 
 	waitForAvailableStart := time.Now()
 	util.WaitForKueueAvailability(ctx, k8sClient)
diff --git a/test/e2e/customconfigs/suite_test.go b/test/e2e/customconfigs/suite_test.go
index 5456f4765..1d84cb7a8 100644
--- a/test/e2e/customconfigs/suite_test.go
+++ b/test/e2e/customconfigs/suite_test.go
@@ -52,7 +52,7 @@ var _ = ginkgo.BeforeSuite(func() {
 	util.SetupLogger()
 
 	k8sClient, _ = util.CreateClientUsingCluster("")
-	ctx = context.Background()
+	ctx = ginkgo.GinkgoT().Context()
 
 	waitForAvailableStart := time.Now()
 	util.WaitForKueueAvailability(ctx, k8sClient)
diff --git a/test/e2e/multikueue/suite_test.go b/test/e2e/multikueue/suite_test.go
index 5c1344562..91a0dbd1c 100644
--- a/test/e2e/multikueue/suite_test.go
+++ b/test/e2e/multikueue/suite_test.go
@@ -267,7 +267,7 @@ var _ = ginkgo.BeforeSuite(func() {
 	worker1RestClient = util.CreateRestClient(worker1Cfg)
 	worker2RestClient = util.CreateRestClient(worker2Cfg)
 
-	ctx = context.Background()
+	ctx = ginkgo.GinkgoT().Context()
 
 	worker1Kconfig, err := kubeconfigForMultiKueueSA(ctx, k8sWorker1Client, worker1Cfg, "kueue-system", "mksa", worker1ClusterName)
 	gomega.Expect(err).NotTo(gomega.HaveOccurred())
diff --git a/test/e2e/singlecluster/suite_test.go b/test/e2e/singlecluster/suite_test.go
index fc08c99f3..0beeb8b68 100644
--- a/test/e2e/singlecluster/suite_test.go
+++ b/test/e2e/singlecluster/suite_test.go
@@ -63,7 +63,7 @@ var _ = ginkgo.BeforeSuite(func() {
 	restClient = util.CreateRestClient(cfg)
 	visibilityClient = util.CreateVisibilityClient("")
 	impersonatedVisibilityClient = util.CreateVisibilityClient("system:serviceaccount:kueue-system:default")
-	ctx = context.Background()
+	ctx = ginkgo.GinkgoT().Context()
 
 	waitForAvailableStart := time.Now()
 	util.WaitForKueueAvailability(ctx, k8sClient)
diff --git a/test/e2e/tas/suite_test.go b/test/e2e/tas/suite_test.go
index 717b18c45..50265cf6b 100644
--- a/test/e2e/tas/suite_test.go
+++ b/test/e2e/tas/suite_test.go
@@ -53,7 +53,7 @@ var _ = ginkgo.BeforeSuite(func() {
 	util.SetupLogger()
 
 	k8sClient, _ = util.CreateClientUsingCluster("")
-	ctx = context.Background()
+	ctx = ginkgo.GinkgoT().Context()
 
 	waitForAvailableStart := time.Now()
 	util.WaitForKueueAvailability(ctx, k8sClient)
diff --git a/test/integration/framework/framework.go b/test/integration/framework/framework.go
index 3c7ac6c50..2a5f4a194 100644
--- a/test/integration/framework/framework.go
+++ b/test/integration/framework/framework.go
@@ -133,7 +133,7 @@ func (f *Framework) SetupClient(cfg *rest.Config) (context.Context, client.Clien
 	gomega.ExpectWithOffset(1, err).NotTo(gomega.HaveOccurred())
 	gomega.ExpectWithOffset(1, k8sClient).NotTo(gomega.BeNil())
 
-	ctx, cancel := context.WithCancel(context.Background())
+	ctx, cancel := context.WithCancel(ginkgo.GinkgoT().Context())
 	f.cancel = cancel
 
 	return ctx, k8sClient