From 2c8a574fff3c532c7180a4ed3196cabd38eae45e Mon Sep 17 00:00:00 2001 From: "Li. Sparks" <15156525868@163.com> Date: Thu, 29 Aug 2024 19:29:18 +0800 Subject: [PATCH] fix: ApplicationSet e2e TestSyncPolicyCreateUpdate&TestSyncPolicyCreateOnly test race condition bug #19577 (#19578) * fixed e2e TestSyncPolicyCreateUpdate&TestSyncPolicyCreateOnly bug Signed-off-by: Li. Sparks <15156525868@163.com> * format Signed-off-by: Li. Sparks <15156525868@163.com> * change the comment, explain why apps still exists Signed-off-by: Li. Sparks <15156525868@163.com> --------- Signed-off-by: Li. Sparks <15156525868@163.com> --- test/e2e/applicationset_test.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/test/e2e/applicationset_test.go b/test/e2e/applicationset_test.go index 90496fa57d5a4..5df36d591b1d9 100644 --- a/test/e2e/applicationset_test.go +++ b/test/e2e/applicationset_test.go @@ -845,7 +845,10 @@ func TestSyncPolicyCreateUpdate(t *testing.T) { Spec: v1alpha1.ApplicationSetSpec{ GoTemplate: true, Template: v1alpha1.ApplicationSetTemplate{ - ApplicationSetTemplateMeta: v1alpha1.ApplicationSetTemplateMeta{Name: "{{.cluster}}-guestbook-sync-policy-create-update"}, + ApplicationSetTemplateMeta: v1alpha1.ApplicationSetTemplateMeta{ + Name: "{{.cluster}}-guestbook-sync-policy-create-update", + Finalizers: []string{"resources-finalizer.argocd.argoproj.io"}, + }, Spec: argov1alpha1.ApplicationSpec{ Project: "default", Source: &argov1alpha1.ApplicationSource{ @@ -913,9 +916,11 @@ func TestSyncPolicyCreateUpdate(t *testing.T) { // verify the ApplicationSet status conditions were set correctly Expect(ApplicationSetHasConditions("sync-policy-create-update", ExpectedConditions)). - // Delete the ApplicationSet, and verify it deletes the Applications + // Delete the ApplicationSet, and verify it not deletes the Applications + // As policy is create-update, AppSet controller will remove all generated applications's ownerReferences on delete AppSet + // So AppSet deletion will be reflected, but all the applications it generates will still exist When(). - Delete().Then().Expect(ApplicationsDoNotExist([]argov1alpha1.Application{*expectedAppNewMetadata})) + Delete().Then().Expect(ApplicationsExist([]argov1alpha1.Application{*expectedAppNewMetadata})) } func TestSyncPolicyCreateDelete(t *testing.T) { @@ -1052,7 +1057,10 @@ func TestSyncPolicyCreateOnly(t *testing.T) { Spec: v1alpha1.ApplicationSetSpec{ GoTemplate: true, Template: v1alpha1.ApplicationSetTemplate{ - ApplicationSetTemplateMeta: v1alpha1.ApplicationSetTemplateMeta{Name: "{{.cluster}}-guestbook-sync-policy-create-only"}, + ApplicationSetTemplateMeta: v1alpha1.ApplicationSetTemplateMeta{ + Name: "{{.cluster}}-guestbook-sync-policy-create-only", + Finalizers: []string{"resources-finalizer.argocd.argoproj.io"}, + }, Spec: argov1alpha1.ApplicationSpec{ Project: "default", Source: &argov1alpha1.ApplicationSource{ @@ -1111,9 +1119,11 @@ func TestSyncPolicyCreateOnly(t *testing.T) { // verify the ApplicationSet status conditions were set correctly Expect(ApplicationSetHasConditions("sync-policy-create-only", ExpectedConditions)). - // Delete the ApplicationSet, and verify it deletes the Applications + // Delete the ApplicationSet, and verify it not deletes the Applications + // As policy is create-update, AppSet controller will remove all generated applications's ownerReferences on delete AppSet + // So AppSet deletion will be reflected, but all the applications it generates will still exist When(). - Delete().Then().Expect(ApplicationsDoNotExist([]argov1alpha1.Application{*expectedAppNewNamespace})) + Delete().Then().Expect(ApplicationsExist([]argov1alpha1.Application{*expectedAppNewNamespace})) } func TestSimpleGitDirectoryGenerator(t *testing.T) {