Skip to content

Commit f5b18e4

Browse files
committed
fix: reduce flaky test by avoiding redundant Cluster updates
The suite test was experiencing flakiness due to intermittent Conflict errors. Added an early-return check within the RetryOnConflict loop. The logic now verifies both the label existence/value and the Spec.Paused status before attempting an update.
1 parent c92a2d3 commit f5b18e4

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

test/fv/fv_suite_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ func verifyCAPICluster() {
190190
if currentLabels == nil {
191191
currentLabels = make(map[string]string)
192192
}
193+
194+
// Early return only if BOTH conditions are already satisfied
195+
val, exists := currentCluster.Labels[key]
196+
if exists && val == value && !isTrue(currentCluster.Spec.Paused) {
197+
return nil
198+
}
199+
193200
currentLabels[key] = value
194201
currentCluster.Labels = currentLabels
195202
paused := false
@@ -200,6 +207,10 @@ func verifyCAPICluster() {
200207
Expect(err).To(BeNil())
201208
}
202209

210+
func isTrue(b *bool) bool {
211+
return b != nil && *b
212+
}
213+
203214
func verifySveltosCluster() {
204215
clusterList := &libsveltosv1beta1.SveltosClusterList{}
205216
listOptions := []client.ListOption{

test/fv/stale_resource_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ var _ = Describe("Stale Resources", func() {
202202
return false
203203
}, timeout, pollingInterval).Should(BeTrue())
204204

205+
Byf("Verifying Service %s is not created the workload cluster", incorrectServiceName)
206+
Consistently(func() bool {
207+
currentService := &corev1.Service{}
208+
err = workloadClient.Get(context.TODO(),
209+
types.NamespacedName{Namespace: configMapNs, Name: incorrectServiceName}, currentService)
210+
return err != nil && apierrors.IsNotFound(err)
211+
}, time.Minute, pollingInterval).ShouldNot(BeNil())
212+
205213
for _, serviceName := range []string{service1, service2, service3} {
206214
Byf("Verifying Service %s is still in the workload cluster", serviceName)
207215
Consistently(func() error {
@@ -211,14 +219,6 @@ var _ = Describe("Stale Resources", func() {
211219
}, time.Minute, pollingInterval).Should(BeNil())
212220
}
213221

214-
Byf("Verifying Service %s is not created the workload cluster", incorrectServiceName)
215-
Consistently(func() bool {
216-
currentService := &corev1.Service{}
217-
err = workloadClient.Get(context.TODO(),
218-
types.NamespacedName{Namespace: configMapNs, Name: incorrectServiceName}, currentService)
219-
return err != nil && apierrors.IsNotFound(err)
220-
}, time.Minute, pollingInterval).ShouldNot(BeNil())
221-
222222
By("Updating ConfigMap to reference also a fourth Service")
223223
service4 := randomString()
224224
Expect(k8sClient.Get(context.TODO(),

0 commit comments

Comments
 (0)