Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test case for TryNextFlavor but flavor is full #2482

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 86 additions & 1 deletion pkg/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2093,6 +2093,7 @@ func TestLastSchedulingContext(t *testing.T) {
ReserveQuota(utiltesting.MakeAdmission("eng-alpha").Assignment(corev1.ResourceCPU, "on-demand", "50").Obj()).
Admitted(true).
Obj()
now := time.Now()
cases := []struct {
name string
cqs []kueue.ClusterQueue
Expand Down Expand Up @@ -2276,6 +2277,90 @@ func TestLastSchedulingContext(t *testing.T) {
"default/new": *utiltesting.MakeAdmission("eng-cohort-theta").Assignment(corev1.ResourceCPU, "on-demand", "20").Obj(),
},
},
{
name: "TryNextFlavor, but second flavor is full and can preempt on first",
cqs: []kueue.ClusterQueue{
*utiltesting.MakeClusterQueue("eng-cohort-alpha").
Cohort("cohort").
Preemption(kueue.ClusterQueuePreemption{
WithinClusterQueue: kueue.PreemptionPolicyLowerPriority,
ReclaimWithinCohort: kueue.PreemptionPolicyAny,
}).
FlavorFungibility(kueue.FlavorFungibility{
WhenCanPreempt: kueue.TryNextFlavor,
WhenCanBorrow: kueue.TryNextFlavor,
}).
ResourceGroup(
*utiltesting.MakeFlavorQuotas("on-demand").
ResourceQuotaWrapper(corev1.ResourceCPU).NominalQuota("0").BorrowingLimit("60").Append().
Obj(),
*utiltesting.MakeFlavorQuotas("spot").
ResourceQuotaWrapper(corev1.ResourceCPU).NominalQuota("30").BorrowingLimit("30").Append().
Obj(),
).Obj(),
*utiltesting.MakeClusterQueue("eng-cohort-beta").
Cohort("cohort").
Preemption(kueue.ClusterQueuePreemption{
WithinClusterQueue: kueue.PreemptionPolicyLowerPriority,
ReclaimWithinCohort: kueue.PreemptionPolicyAny,
}).
FlavorFungibility(kueue.FlavorFungibility{
WhenCanPreempt: kueue.TryNextFlavor,
WhenCanBorrow: kueue.TryNextFlavor,
}).
ResourceGroup(
*utiltesting.MakeFlavorQuotas("on-demand").
ResourceQuotaWrapper(corev1.ResourceCPU).NominalQuota("30").BorrowingLimit("30").Append().
Obj(),
*utiltesting.MakeFlavorQuotas("spot").
ResourceQuotaWrapper(corev1.ResourceCPU).NominalQuota("30").BorrowingLimit("30").Append().
Obj(),
).Obj(),
*utiltesting.MakeClusterQueue("eng-cohort-shared").
Cohort("cohort").
ResourceGroup(
*utiltesting.MakeFlavorQuotas("on-demand").
ResourceQuotaWrapper(corev1.ResourceCPU).NominalQuota("30").Append().
Obj(),
).Obj(),
},
admittedWorkloads: []kueue.Workload{
*utiltesting.MakeWorkload("alpha1", "default").
Request(corev1.ResourceCPU, "22").
SimpleReserveQuota("eng-cohort-alpha", "on-demand", now.Add(-time.Second)).
Admitted(true).
Obj(),
*utiltesting.MakeWorkload("alpha2", "default").
Request(corev1.ResourceCPU, "22").
SimpleReserveQuota("eng-cohort-alpha", "on-demand", now).
Admitted(true).
Obj(),
*utiltesting.MakeWorkload("alpha3", "default").
Request(corev1.ResourceCPU, "22").
SimpleReserveQuota("eng-cohort-alpha", "spot", now).
Admitted(true).
Obj(),
*utiltesting.MakeWorkload("beta1", "default").
Request(corev1.ResourceCPU, "22").
SimpleReserveQuota("eng-cohort-beta", "spot", now).
Admitted(true).
Obj(),
},
workloads: []kueue.Workload{
*utiltesting.MakeWorkload("new", "default").
Queue("main-beta").
Request(corev1.ResourceCPU, "22").
Obj(),
},
deleteWorkloads: []kueue.Workload{*utiltesting.MakeWorkload("alpha2", "default").Obj()},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is deleteWorkloads testing anything useful in this case, or can we omit it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It marks the termination of alpha2, so that the incoming workload can be admitted.

wantPreempted: sets.New("default/alpha2"),
wantAdmissionsOnSecondSchedule: map[string]kueue.Admission{
"default/alpha1": *utiltesting.MakeAdmission("eng-cohort-alpha").Assignment(corev1.ResourceCPU, "on-demand", "22").Obj(),
"default/alpha3": *utiltesting.MakeAdmission("eng-cohort-alpha").Assignment(corev1.ResourceCPU, "spot", "22").Obj(),
"default/beta1": *utiltesting.MakeAdmission("eng-cohort-beta").Assignment(corev1.ResourceCPU, "spot", "22").Obj(),
"default/new": *utiltesting.MakeAdmission("eng-cohort-beta").Assignment(corev1.ResourceCPU, "on-demand", "22").Obj(),
},
},
}

for _, tc := range cases {
Expand Down Expand Up @@ -2346,7 +2431,7 @@ func TestLastSchedulingContext(t *testing.T) {
if diff := cmp.Diff(tc.wantPreempted, gotPreempted); diff != "" {
t.Errorf("Unexpected preemptions (-want,+got):\n%s", diff)
}
if diff := cmp.Diff(tc.wantAdmissionsOnFirstSchedule, gotScheduled); diff != "" {
if diff := cmp.Diff(tc.wantAdmissionsOnFirstSchedule, gotScheduled, cmpopts.EquateEmpty()); diff != "" {
t.Errorf("Unexpected scheduled workloads (-want,+got):\n%s", diff)
}

Expand Down