Skip to content

Commit 5dbb7b6

Browse files
committed
Updates since removing the WaitForRunningPodCount helper
Removed WaitForRunningPodCount and opted to go with WaitForScaledJobCount followed by WaitForAllPodRunningInNamespace since that keeps the changes a bit more concise and works for what this test needs. Issue #3661 Signed-off-by: jansworld <navon.josh@gmail.com>
1 parent 4f3f91d commit 5dbb7b6

2 files changed

Lines changed: 9 additions & 33 deletions

File tree

tests/helper/helper.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -490,36 +490,6 @@ func WaitForAllPodRunningInNamespace(t *testing.T, kc *kubernetes.Clientset, nam
490490
return false
491491
}
492492

493-
// Waits until the target number of pods is running. If running pod count differs from target, returns false.
494-
func WaitForRunningPodCount(t *testing.T, kc *kubernetes.Clientset, scaledJobName, namespace string, target, iterations, interval int) bool {
495-
for i := 0; i < iterations; i++ {
496-
pods, err := kc.CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{
497-
LabelSelector: fmt.Sprintf("scaledjob.keda.sh/name=%s", scaledJobName),
498-
})
499-
if err != nil {
500-
t.Logf("cannot list pods - %s", err)
501-
}
502-
503-
runningPodCount := 0
504-
for _, pod := range pods.Items {
505-
if pod.Status.Phase == corev1.PodRunning {
506-
runningPodCount++
507-
}
508-
}
509-
510-
t.Logf("Waiting for running pods. Namespace - %s, Current - %d, Target - %d",
511-
namespace, runningPodCount, target)
512-
if runningPodCount == target {
513-
return true
514-
} else if runningPodCount > target {
515-
return false
516-
}
517-
518-
time.Sleep(time.Duration(interval) * time.Second)
519-
}
520-
return false
521-
}
522-
523493
// Waits until the Horizontal Pod Autoscaler for the scaledObject reports that it has metrics available
524494
// to calculate, or until the number of iterations are done, whichever happens first.
525495
func WaitForHPAMetricsToPopulate(t *testing.T, kc *kubernetes.Clientset, name, namespace string, iterations, intervalSeconds int) bool {

tests/internals/scaling_strategies/accurate_scaling_strategy/accurate_scaling_strategy_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,10 @@ func testAccurateScaling(ctx context.Context, t *testing.T, kc *kubernetes.Clien
134134

135135
// Base case (number of scale = maxScale since pendingJobs = 0)
136136
enqueueMessages(ctx, t, client, 4)
137-
assert.True(t, WaitForRunningPodCount(t, kc, scaledJobName, testNamespace, 4, iterationCount, 1),
137+
assert.True(t, WaitForScaledJobCount(t, kc, scaledJobName, testNamespace, 4, iterationCount, 1),
138138
"job count should be %d after %d iterations", 4, iterationCount)
139+
assert.True(t, WaitForAllPodRunningInNamespace(t, kc, testNamespace, iterationCount, 1),
140+
"all scaledjob pods should be running after %d iterations", iterationCount)
139141

140142
// Clear the queue to simulate message consumption and wait for job completion
141143
_, err := client.ClearMessages(ctx, nil)
@@ -144,17 +146,21 @@ func testAccurateScaling(ctx context.Context, t *testing.T, kc *kubernetes.Clien
144146

145147
// Test the cap condition (maxScale + runningJobs > maxReplicaCount)
146148
enqueueMessages(ctx, t, client, 4)
147-
assert.True(t, WaitForRunningPodCount(t, kc, scaledJobName, testNamespace, 4, iterationCount, 1),
149+
assert.True(t, WaitForScaledJobCount(t, kc, scaledJobName, testNamespace, 4, iterationCount, 1),
148150
"running job count should be %d after %d iterations", 4, iterationCount)
151+
assert.True(t, WaitForAllPodRunningInNamespace(t, kc, testNamespace, iterationCount, 1),
152+
"all scaledjob pods should be running after %d iterations", iterationCount)
149153

150154
// Clear the messages to simulate message consumption
151155
_, err = client.ClearMessages(ctx, nil)
152156
assert.NoErrorf(t, err, "cannot clear queue - %s", err)
153157

154158
// Queue up 8 more messages to trigger the cap condition
155159
enqueueMessages(ctx, t, client, 8)
156-
assert.True(t, WaitForRunningPodCount(t, kc, scaledJobName, testNamespace, 10, iterationCount, 1),
160+
assert.True(t, WaitForScaledJobCount(t, kc, scaledJobName, testNamespace, 10, iterationCount, 1),
157161
"running job count should be %d after %d iterations", 10, iterationCount)
162+
assert.True(t, WaitForAllPodRunningInNamespace(t, kc, testNamespace, iterationCount, 1),
163+
"all scaledjob pods should be running after %d iterations", iterationCount)
158164

159165
// Message cleanup and wait for jobs to complete
160166
_, err = client.ClearMessages(ctx, nil)

0 commit comments

Comments
 (0)