Skip to content

Commit

Permalink
make ut more robust
Browse files Browse the repository at this point in the history
Signed-off-by: AiRanthem <zhongtianyun.zty@alibaba-inc.com>
  • Loading branch information
AiRanthem committed Oct 9, 2024
1 parent b4968fd commit f9f8a70
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ func TestUnschedulableStatusManagement(t *testing.T) {
return subset, ud
},
expectPendingPods: 0,
requeueUpperLimit: 15 * time.Second,
requeueLowerLimit: 14 * time.Second,
requeueUpperLimit: appsv1alpha1.DefaultRescheduleCriticalDuration - 15*time.Second + 100*time.Millisecond,
requeueLowerLimit: appsv1alpha1.DefaultRescheduleCriticalDuration - 15*time.Second - 100*time.Millisecond,
unschedulable: false,
},
{
Expand Down Expand Up @@ -232,8 +232,8 @@ func TestUnschedulableStatusManagement(t *testing.T) {
return subset, ud
},
expectPendingPods: 0,
requeueUpperLimit: appsv1alpha1.DefaultUnschedulableStatusLastDuration - time.Minute,
requeueLowerLimit: 59*time.Second + appsv1alpha1.DefaultUnschedulableStatusLastDuration - 2*time.Minute,
requeueUpperLimit: appsv1alpha1.DefaultUnschedulableStatusLastDuration - time.Minute + time.Second,
requeueLowerLimit: appsv1alpha1.DefaultUnschedulableStatusLastDuration - time.Minute - time.Second,
unschedulable: true,
},
{
Expand Down Expand Up @@ -269,15 +269,23 @@ func TestUnschedulableStatusManagement(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
subset, ud := c.envFactory()
start := time.Now()
manageUnschedulableStatusForExistingSubset(subset.Name, subset, ud)
cost := time.Now().Sub(start)
if subset.Status.UnschedulableStatus.PendingPods != c.expectPendingPods {
t.Logf("case %s failed: expect pending pods %d, but got %d", c.name, c.expectPendingPods, subset.Status.UnschedulableStatus.PendingPods)
t.Fail()
}
requeueAfter := durationStore.Pop(getUnitedDeploymentKey(ud))
if c.requeueUpperLimit != c.requeueLowerLimit {
// result is not a const, which means this case will be affected by low execution speed.
requeueAfter += cost
} else {
cost = 0
}
t.Logf("got requeueAfter %f not in range [%f, %f] (cost fix %f)",
requeueAfter.Seconds(), c.requeueLowerLimit.Seconds(), c.requeueUpperLimit.Seconds(), cost.Seconds())
if requeueAfter > c.requeueUpperLimit || requeueAfter < c.requeueLowerLimit {
t.Logf("case %s failed: got requeueAfter %f not in range [%f, %f]", c.name, requeueAfter.Seconds(),
c.requeueLowerLimit.Seconds(), c.requeueUpperLimit.Seconds())
t.Fail()
}
if subset.Status.UnschedulableStatus.Unschedulable != c.unschedulable {
Expand Down

0 comments on commit f9f8a70

Please sign in to comment.