test(e2e): ExpectConsistency was not consistent (#26778)

Signed-off-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com>
This commit is contained in:
Alexandre Gaudreault 2026-03-10 15:44:15 -04:00 committed by GitHub
parent 18fe8c4e34
commit 95c17b68f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 12 deletions

View file

@ -3087,11 +3087,9 @@ func TestDeletionConfirmation(t *testing.T) {
t.Context(), &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "test-configmap",
Labels: map[string]string{
common.LabelKeyAppInstance: ctx.AppName(),
},
Annotations: map[string]string{
AnnotationSyncOptions: "Prune=confirm",
common.AnnotationKeyAppInstance: fmt.Sprintf("%s:/ConfigMap:%s/test-configmap", ctx.GetName(), ctx.DeploymentNamespace()),
AnnotationSyncOptions: "Prune=confirm",
},
},
}, metav1.CreateOptions{})
@ -3102,7 +3100,8 @@ func TestDeletionConfirmation(t *testing.T) {
When().
PatchFile("guestbook-ui-deployment.yaml", `[{ "op": "add", "path": "/metadata/annotations", "value": { "argocd.argoproj.io/sync-options": "Delete=confirm" }}]`).
CreateApp().Sync().
Then().ExpectConsistently(OperationPhaseIs(OperationRunning), time.Second, 5*time.Second).
Then().
ExpectConsistently(OperationPhaseIs(OperationRunning), time.Second, 5*time.Second).
When().ConfirmDeletion().
Then().Expect(OperationPhaseIs(OperationSucceeded)).
Expect(SyncStatusIs(SyncStatusCodeSynced)).

View file

@ -443,9 +443,10 @@ func (a *Actions) ConfirmDeletion() *Actions {
a.runCli("app", "confirm-deletion", a.context.AppQualifiedName())
// Always sleep more than a second after the confirmation so the timestamp
// is not valid for immediate subsequent operations
time.Sleep(1500 * time.Millisecond)
// Always sleep a few seconds after the confirmation so the timestamp
// is not valid for immediate subsequent operations.
// Kubernetes containers may have clocks with a few seconds difference, and we want to avoid race conditions.
time.Sleep(3 * time.Second)
return a
}

View file

@ -58,18 +58,21 @@ func (c *Consequences) Expect(e Expectation) *Consequences {
return c
}
// ExpectConsistently will continuously evaluate a condition, and it must be true each time it is evaluated, otherwise the test is failed. The condition will be repeatedly evaluated until 'expirationDuration' is met, waiting 'waitDuration' after each success.
// ExpectConsistently will continuously evaluate a condition. Once true, it must be true each time it is evaluated, otherwise the test is failed.
// The condition will be repeatedly evaluated once it is true,until 'expirationDuration' is met, waiting 'waitDuration' after each success.
func (c *Consequences) ExpectConsistently(e Expectation, waitDuration time.Duration, expirationDuration time.Duration) *Consequences {
// this invocation makes sure this func is not reported as the cause of the failure - we are a "test helper"
c.context.T().Helper()
c.Expect(e) // ensure the condition is true before expecting consistency
expiration := time.Now().Add(expirationDuration)
for time.Now().Before(expiration) {
state, message := e(c)
switch state {
case succeeded:
log.Infof("expectation succeeded: %s", message)
case failed:
default:
c.context.T().Fatalf("failed expectation: %s", message)
return c
}

View file

@ -167,7 +167,6 @@ func TestAutomatedSelfHealingAgainstAnnotatedTag(t *testing.T) {
app.Spec.SyncPolicy = &SyncPolicy{Automated: &SyncPolicyAutomated{Prune: true, SelfHeal: false}}
}).
Then().
Expect(SyncStatusIs(SyncStatusCodeSynced)).
ExpectConsistently(SyncStatusIs(SyncStatusCodeSynced), WaitDuration, time.Second*10).
When().
// Update the annotated tag to a new git commit, that has a new revisionHistoryLimit.
@ -220,7 +219,6 @@ func TestAutomatedSelfHealingAgainstLightweightTag(t *testing.T) {
app.Spec.SyncPolicy = &SyncPolicy{Automated: &SyncPolicyAutomated{Prune: true, SelfHeal: false}}
}).
Then().
Expect(SyncStatusIs(SyncStatusCodeSynced)).
ExpectConsistently(SyncStatusIs(SyncStatusCodeSynced), WaitDuration, time.Second*10).
When().
// Update the annotated tag to a new git commit, that has a new revisionHistoryLimit.