diff --git a/internal/pkg/victims/victims.go b/internal/pkg/victims/victims.go index 977e3b20..ef2ae406 100644 --- a/internal/pkg/victims/victims.go +++ b/internal/pkg/victims/victims.go @@ -281,7 +281,7 @@ func (v *VictimBase) KillNumberForFixedPercentage(clientset kube.Interface, kill } numberOfPodsToKill := float64(numRunningPods) * float64(killPercentage) / 100 - killNum := int(math.Floor(numberOfPodsToKill)) + killNum := int(math.Round(numberOfPodsToKill)) return killNum, nil } @@ -305,7 +305,7 @@ func (v *VictimBase) KillNumberForMaxPercentage(clientset kube.Interface, maxPer r := rand.New(rand.NewSource(time.Now().UnixNano())) killPercentage := r.Intn(maxPercentage + 1) // + 1 because Intn works with half open interval [0,n) and we want [0,n] numberOfPodsToKill := float64(numRunningPods) * float64(killPercentage) / 100 - killNum := int(math.Floor(numberOfPodsToKill)) + killNum := int(math.Round(numberOfPodsToKill)) return killNum, nil } diff --git a/internal/pkg/victims/victims_test.go b/internal/pkg/victims/victims_test.go index 4d2548d2..f54ecafa 100644 --- a/internal/pkg/victims/victims_test.go +++ b/internal/pkg/victims/victims_test.go @@ -258,7 +258,7 @@ func TestDeletePodsFixedPercentage(t *testing.T) { pods: append( generateNPods("running", 1, corev1.PodRunning), generateNPods("pending", 1, corev1.PodPending)...), - expectedNum: 0, + expectedNum: 1, expectedErr: false, }, }