Skip to content

Commit 7c87c61

Browse files
authored
Helper: replace the last sleeping loop with the consistency helper its only caller needs (#8183)
WaitForDeploymentReplicaCountChange was the one loop in tests/helper still timed by time.Sleep after #8068 and #8085. It polled a deployment for a fixed number of iterations and returned the replica count at the point it first changed, or the last count seen when the iterations ran out. Its only remaining caller, azure_workload_identity_user_assigned, compares that count to 0 after 30 x 1s to check that a ScaledObject with the wrong identity does not scale the deployment out. That is a "stays at 0 for the window" assertion, and AssertReplicaCountNotChangeDuringTimePeriod already expresses exactly that on top of KedaConsistently: it observes the count on every attempt inside the window instead of only reporting the first change, and it does not fold a failed read into a 0 that looks like a scale to zero. The caller now uses it with the same 30s window; the message that claimed a minute was describing the loop wrongly. With no callers left, the helper is removed rather than converted. Its name suggested a wait for a change, while the two callers it had left both used it to assert that nothing changed, and #8110 already had to fix the other one, which called it with the arguments transposed into a no-op. tests/helper/helper.go no longer contains a time.Sleep. Relates to #7991 Signed-off-by: Mikhail Fedosin <mfedosin@redhat.com>
1 parent 96b94e4 commit 7c87c61

2 files changed

Lines changed: 4 additions & 33 deletions

File tree

‎tests/helper/helper.go‎

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -730,36 +730,6 @@ func WaitForReplicaSetReplicaReadyCount(t *testing.T, kc *kubernetes.Clientset,
730730
})
731731
}
732732

733-
// Waits for number of iterations and returns replica count.
734-
func WaitForDeploymentReplicaCountChange(t *testing.T, kc *kubernetes.Clientset, name, namespace string, iterations, intervalSeconds int) int {
735-
t.Log("Waiting for some time to see if deployment replica count changes")
736-
var replicas, prevReplicas int32
737-
prevReplicas = -1
738-
739-
for i := 0; i < iterations; i++ {
740-
deployment, err := kc.AppsV1().Deployments(namespace).Get(context.Background(), name, metav1.GetOptions{})
741-
if err != nil {
742-
// Reading on would report 0 replicas, which the caller cannot tell apart from a
743-
// genuine scale to zero.
744-
t.Logf("cannot get deployment %s/%s - %s", namespace, name, err)
745-
} else {
746-
replicas = deployment.Status.Replicas
747-
748-
t.Logf("Deployment - %s, Current - %d", name, replicas)
749-
750-
if replicas != prevReplicas && prevReplicas != -1 {
751-
break
752-
}
753-
754-
prevReplicas = replicas
755-
}
756-
757-
time.Sleep(time.Duration(intervalSeconds) * time.Second)
758-
}
759-
760-
return int(replicas)
761-
}
762-
763733
// Waits some time to ensure that the replica count doesn't change.
764734
func AssertReplicaCountNotChangeDuringTimePeriod(t *testing.T, kc *kubernetes.Clientset, name, namespace string, target, intervalSeconds int) {
765735
t.Logf("Waiting for some time to ensure deployment replica count doesn't change from %d", target)

‎tests/secret-providers/azure_workload_identity_user_assigned/azure_workload_identity_user_assigned_test.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,10 @@ func testScaleOutWithIncorrectIdentity(t *testing.T, kc *kubernetes.Clientset, c
188188
}, nil)
189189
}
190190

191-
// scale out should fail as we are using the incorrect identity
192-
assert.True(t, WaitForDeploymentReplicaCountChange(t, kc, deploymentName, testNamespace, 30, 1) == 0,
193-
"replica count should be 0 after 1 minute")
191+
// Scale out should fail as we are using the incorrect identity, so the replica count has to stay
192+
// at 0 for the whole window rather than merely be 0 at the end of it. Thirty seconds is what the
193+
// previous 30 x 1s wait allowed.
194+
AssertReplicaCountNotChangeDuringTimePeriod(t, kc, deploymentName, testNamespace, 0, 30)
194195
}
195196

196197
func testScaleOutWithCorrectIdentity(t *testing.T, kc *kubernetes.Clientset, data templateData) {

0 commit comments

Comments
 (0)