chore: use testCtx instead of context.TODO()

This commit is contained in:
googs1025 2024-07-09 14:44:49 +08:00
parent 8d0ee91fc7
commit 15cc77603e
3 changed files with 7 additions and 8 deletions

View File

@ -1691,7 +1691,7 @@ func TestBindPlugin(t *testing.T) {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
t.Fatalf("Expected the pod to be scheduled. error: %v", err)
}
pod, err = testCtx.ClientSet.CoreV1().Pods(pod.Namespace).Get(context.TODO(), pod.Name, metav1.GetOptions{})
pod, err = testCtx.ClientSet.CoreV1().Pods(pod.Namespace).Get(testCtx.Ctx, pod.Name, metav1.GetOptions{})
if err != nil {
t.Errorf("can't get pod: %v", err)
}
@ -2571,7 +2571,7 @@ func TestActivatePods(t *testing.T) {
name := fmt.Sprintf("executor-%v", i)
executor := st.MakePod().Name(name).Namespace(ns).Label("executor", "").Container(pause).Obj()
pods = append(pods, executor)
if _, err := cs.CoreV1().Pods(executor.Namespace).Create(context.TODO(), executor, metav1.CreateOptions{}); err != nil {
if _, err := cs.CoreV1().Pods(executor.Namespace).Create(testCtx.Ctx, executor, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create pod %v: %v", executor.Name, err)
}
}
@ -2586,7 +2586,7 @@ func TestActivatePods(t *testing.T) {
// Create a driver pod.
driver := st.MakePod().Name("driver").Namespace(ns).Label("driver", "").Container(pause).Obj()
pods = append(pods, driver)
if _, err := cs.CoreV1().Pods(driver.Namespace).Create(context.TODO(), driver, metav1.CreateOptions{}); err != nil {
if _, err := cs.CoreV1().Pods(driver.Namespace).Create(testCtx.Ctx, driver, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create pod %v: %v", driver.Name, err)
}

View File

@ -1201,7 +1201,7 @@ func TestNominatedNodeCleanUp(t *testing.T) {
// Delete the node if necessary.
if tt.deleteNode {
if err := cs.CoreV1().Nodes().Delete(context.TODO(), nodeName, *metav1.NewDeleteOptions(0)); err != nil {
if err := cs.CoreV1().Nodes().Delete(testCtx.Ctx, nodeName, *metav1.NewDeleteOptions(0)); err != nil {
t.Fatalf("Node %v cannot be deleted: %v", nodeName, err)
}
}
@ -1457,7 +1457,7 @@ func TestPDBInPreemption(t *testing.T) {
}
// Add pod condition ready so that PDB is updated.
addPodConditionReady(p)
if _, err := testCtx.ClientSet.CoreV1().Pods(testCtx.NS.Name).UpdateStatus(context.TODO(), p, metav1.UpdateOptions{}); err != nil {
if _, err := testCtx.ClientSet.CoreV1().Pods(testCtx.NS.Name).UpdateStatus(testCtx.Ctx, p, metav1.UpdateOptions{}); err != nil {
t.Fatal(err)
}
}
@ -1468,7 +1468,7 @@ func TestPDBInPreemption(t *testing.T) {
// Create PDBs.
for _, pdb := range test.pdbs {
_, err := testCtx.ClientSet.PolicyV1().PodDisruptionBudgets(testCtx.NS.Name).Create(context.TODO(), pdb, metav1.CreateOptions{})
_, err := testCtx.ClientSet.PolicyV1().PodDisruptionBudgets(testCtx.NS.Name).Create(testCtx.Ctx, pdb, metav1.CreateOptions{})
if err != nil {
t.Fatalf("Failed to create PDB: %v", err)
}

View File

@ -561,7 +561,6 @@ func TestNodeEvents(t *testing.T) {
// 4. Remove the taint from node2; pod2 should now schedule on node2
testCtx := testutils.InitTestSchedulerWithNS(t, "node-events")
defer testCtx.ClientSet.CoreV1().Nodes().DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{})
// 1.1 create pod1
pod1, err := testutils.CreatePausePodWithResource(testCtx.ClientSet, "pod1", testCtx.NS.Name, &v1.ResourceList{
@ -620,7 +619,7 @@ func TestNodeEvents(t *testing.T) {
Req(map[v1.ResourceName]string{v1.ResourceCPU: "40m"}).
NodeAffinityIn("affinity-key", []string{"affinity-value"}).
Toleration("taint-key").Obj()
plugPod, err = testCtx.ClientSet.CoreV1().Pods(plugPod.Namespace).Create(context.TODO(), plugPod, metav1.CreateOptions{})
plugPod, err = testCtx.ClientSet.CoreV1().Pods(plugPod.Namespace).Create(testCtx.Ctx, plugPod, metav1.CreateOptions{})
if err != nil {
t.Fatalf("Failed to create pod %v: %v", plugPod.Name, err)
}