Repository: kubernetes/kubernetes
File: pkg/scheduler/schedule_one_test.go (Go)

Code before:
			mockScheduleResult: emptyScheduleResult,
			eventReason:        "FailedScheduling",
		},
		{
			name: "pod with existing nominated node name on scheduling error clears nomination",
			sendPod: func() *v1.Pod {
				p := podWithID("foo", "")
				p.Status.NominatedNodeName = "existing-node"
				return p
			}(),
			injectSchedulingError: schedulingErr,
			mockScheduleResult:    scheduleResultOk,
			expectError:           schedulingErr,
			expectErrorPod: func() *v1.Pod {
				p := podWithID("foo", "")
				p.Status.NominatedNodeName = "existing-node"
				return p
			}(),
			expectPodInBackoffQ: func() *v1.Pod {
				p := podWithID("foo", "")
				p.Status.NominatedNodeName = "existing-node"
				return p
			}(),
			// Depending on the timing, if asyncAPICallsEnabled, the NNN update might not be sent yet while checking the expectNominatedNodeName.
			// So, asyncAPICallsEnabled is set to false.
			// TODO: create a method on APIDispatcher to wait for all API calls to finish to ease testing.
			asyncAPICallsEnabled:    ptr.To(false),
			expectNominatedNodeName: "",
			eventReason:             "FailedScheduling",
		},
	}

	type schedFeatures struct {
		asyncAPICallsEnabled                   bool
		nominatedNodeNameForExpectationEnabled bool
	}

	withWorkloadRef := func(pod *v1.Pod, ref *v1.WorkloadReference) *v1.Pod {
		if pod == nil {
			return nil
		}
		newPod := pod.DeepCopy()
		newPod.Spec.WorkloadRef = ref
		return newPod
	}

	testFunc := func(t *testing.T, item testItem, scheduleAsPodGroup bool, features schedFeatures) {
		logger, ctx := ktesting.NewTestContext(t)
		var gotError error
		var gotPod *v1.Pod
		var gotForgetPod *v1.Pod

Review comment (suggestion):
```suggestion
			// TODO(Argh4k): create a method on APIDispatcher to wait for all API calls to finish to ease testing.
```

Code after:
			mockScheduleResult: emptyScheduleResult,
			eventReason:        "FailedScheduling",
		},
		{
			name: "pod with existing nominated node name on scheduling error clears nomination",
			sendPod: func() *v1.Pod {
				p := podWithID("foo", "")
				p.Status.NominatedNodeName = "existing-node"
				return p
			}(),
			injectSchedulingError: schedulingErr,
			mockScheduleResult:    scheduleResultOk,
			expectError:           schedulingErr,
			expectErrorPod: func() *v1.Pod {
				p := podWithID("foo", "")
				p.Status.NominatedNodeName = "existing-node"
				return p
			}(),
			expectPodInBackoffQ: func() *v1.Pod {
				p := podWithID("foo", "")
				p.Status.NominatedNodeName = "existing-node"
				return p
			}(),
			// Depending on the timing, if asyncAPICallsEnabled, the NNN update might not be sent yet while checking the expectNominatedNodeName.
			// So, asyncAPICallsEnabled is set to false.
			// TODO(Argh4k): create a method on APIDispatcher to wait for all API calls to finish to ease testing.
			asyncAPICallsEnabled:    ptr.To(false),
			expectNominatedNodeName: "",
			eventReason:             "FailedScheduling",
		},
	}

	type schedFeatures struct {
		asyncAPICallsEnabled                   bool
		nominatedNodeNameForExpectationEnabled bool
	}

	withWorkloadRef := func(pod *v1.Pod, ref *v1.WorkloadReference) *v1.Pod {
		if pod == nil {
			return nil
		}
		newPod := pod.DeepCopy()
		newPod.Spec.WorkloadRef = ref
		return newPod
	}

	testFunc := func(t *testing.T, item testItem, scheduleAsPodGroup bool, features schedFeatures) {
		logger, ctx := ktesting.NewTestContext(t)
		var gotError error
		var gotPod *v1.Pod
		var gotForgetPod *v1.Pod