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

Code before:
			close(called)
		})
		if err != nil {
			t.Fatal(err)
		}
		informerFactory.Start(ctx.Done())
		informerFactory.WaitForCacheSync(ctx.Done())
		sched.nodeInfoSnapshot = internalcache.NewEmptySnapshot()
		sched.ScheduleOne(ctx)

		if item.postSchedulingCycle != nil {
			item.postSchedulingCycle(ctx, sched)
		}

		if item.podToAdmit != nil {
			for {
				if waitingPod := sched.Profiles[testSchedulerName].GetWaitingPod(item.podToAdmit.pod); waitingPod != nil {
					waitingPod.Allow(item.podToAdmit.pluginName)
					break
				}
			}
		}

		<-called

		// TODO: Re-enable this assumption for item.expectError != nil once solution to
		// https://github.com/kubernetes/kubernetes/issues/137125 is agreed upon and implemented.
		// Right now, handleSchedulingFailure does not guarantee that all updates
		// to nominated nodes will be send out as patch calls as its:
		// - refreshes pod with data from informer cache that can be not up to date
		// - with async calls enabled the previous update to NNN can still be sitting in async queue
		mu.Lock()
		// Cases with expected error are tested below
		if item.expectError == nil && item.expectNominatedNodeName != updatedNominatedNodeName {
			t.Errorf("Expected nominated node name %q, got %q", item.expectNominatedNodeName, updatedNominatedNodeName)
		}
		mu.Unlock()

		// When a pod is scheduled as a pod group, it is assumed first in the snapshot,
		// meaning that assumed and forgotten pods obtained from cache would be nil in some cases.
		// It also sometimes differently sets nodeName on an error pod,
		// which is irrelevant for the actual correctness.
		if !scheduleAsPodGroup {
			if diff := cmp.Diff(item.expectAssumedPod, gotAssumedPod); diff != "" {
				t.Errorf("Unexpected assumed pod (-want,+got):\n%s", diff)
			}
			if diff := cmp.Diff(item.expectErrorPod, gotPod); diff != "" {
				t.Errorf("Unexpected error pod (-want,+got):\n%s", diff)
			}
			if diff := cmp.Diff(item.expectForgetPod, gotForgetPod); diff != "" {
				t.Errorf("Unexpected forget pod (-want,+got):\n%s", diff)

Review comment (suggestion):
```suggestion
		// TODO(Argh4k): Re-enable this assumption for item.expectError != nil once solution to
```

Code after:
			close(called)
		})
		if err != nil {
			t.Fatal(err)
		}
		informerFactory.Start(ctx.Done())
		informerFactory.WaitForCacheSync(ctx.Done())
		sched.nodeInfoSnapshot = internalcache.NewEmptySnapshot()
		sched.ScheduleOne(ctx)

		if item.postSchedulingCycle != nil {
			item.postSchedulingCycle(ctx, sched)
		}

		if item.podToAdmit != nil {
			for {
				if waitingPod := sched.Profiles[testSchedulerName].GetWaitingPod(item.podToAdmit.pod); waitingPod != nil {
					waitingPod.Allow(item.podToAdmit.pluginName)
					break
				}
			}
		}

		<-called

		// TODO(Argh4k): Re-enable this assumption for item.expectError != nil once solution to
		// https://github.com/kubernetes/kubernetes/issues/137125 is agreed upon and implemented.
		// Right now, handleSchedulingFailure does not guarantee that all updates
		// to nominated nodes will be send out as patch calls as its:
		// - refreshes pod with data from informer cache that can be not up to date
		// - with async calls enabled the previous update to NNN can still be sitting in async queue
		mu.Lock()
		// Cases with expected error are tested below
		if item.expectError == nil && item.expectNominatedNodeName != updatedNominatedNodeName {
			t.Errorf("Expected nominated node name %q, got %q", item.expectNominatedNodeName, updatedNominatedNodeName)
		}
		mu.Unlock()

		// When a pod is scheduled as a pod group, it is assumed first in the snapshot,
		// meaning that assumed and forgotten pods obtained from cache would be nil in some cases.
		// It also sometimes differently sets nodeName on an error pod,
		// which is irrelevant for the actual correctness.
		if !scheduleAsPodGroup {
			if diff := cmp.Diff(item.expectAssumedPod, gotAssumedPod); diff != "" {
				t.Errorf("Unexpected assumed pod (-want,+got):\n%s", diff)
			}
			if diff := cmp.Diff(item.expectErrorPod, gotPod); diff != "" {
				t.Errorf("Unexpected error pod (-want,+got):\n%s", diff)
			}
			if diff := cmp.Diff(item.expectForgetPod, gotForgetPod); diff != "" {
				t.Errorf("Unexpected forget pod (-want,+got):\n%s", diff)