From a1147f60e989f975db503d532a1c07b53b4a7213 Mon Sep 17 00:00:00 2001 From: Andrii Korotkov Date: Sat, 30 Nov 2024 04:46:17 -0800 Subject: [PATCH] chore: Remove or reduce sleep in e2e tests Closes #21009 Some sleeps may no longer be necessary or be too long. Try removing or reducing duration. Signed-off-by: Andrii Korotkov --- test/e2e/app_management_ns_test.go | 3 +- test/e2e/app_management_test.go | 2 +- test/e2e/applicationset_test.go | 16 ++++---- test/e2e/cluster_test.go | 4 +- test/e2e/custom_tool_test.go | 39 +++++++------------ .../fixture/applicationsets/utils/fixture.go | 19 ++++++++- test/e2e/fixture/fixture.go | 2 +- test/e2e/hook_test.go | 2 +- test/e2e/project_management_test.go | 8 ---- 9 files changed, 46 insertions(+), 49 deletions(-) diff --git a/test/e2e/app_management_ns_test.go b/test/e2e/app_management_ns_test.go index bc01522a3a0d3..6c793313efc4d 100644 --- a/test/e2e/app_management_ns_test.go +++ b/test/e2e/app_management_ns_test.go @@ -1696,7 +1696,6 @@ func TestNamespacedCreateAppWithNoNameSpaceForGlobalResource(t *testing.T) { CreateWithNoNameSpace(). Then(). And(func(app *Application) { - time.Sleep(500 * time.Millisecond) app, err := AppClientset.ArgoprojV1alpha1().Applications(AppNamespace()).Get(context.Background(), app.Name, metav1.GetOptions{}) require.NoError(t, err) assert.Empty(t, app.Status.Conditions) @@ -2439,7 +2438,6 @@ func TestNamespacedDisableManifestGeneration(t *testing.T) { }). When(). And(func() { - time.Sleep(3 * time.Second) SetEnableManifestGeneration(map[ApplicationSourceType]bool{ ApplicationSourceTypeKustomize: false, }) @@ -2447,6 +2445,7 @@ func TestNamespacedDisableManifestGeneration(t *testing.T) { Refresh(RefreshTypeHard). Then(). And(func(app *Application) { + // Wait for refresh to complete time.Sleep(1 * time.Second) }). And(func(app *Application) { diff --git a/test/e2e/app_management_test.go b/test/e2e/app_management_test.go index 92fa87f01c1bf..aee699219207f 100644 --- a/test/e2e/app_management_test.go +++ b/test/e2e/app_management_test.go @@ -2107,7 +2107,6 @@ func TestCreateAppWithNoNameSpaceForGlobalResource(t *testing.T) { CreateWithNoNameSpace(). Then(). And(func(app *Application) { - time.Sleep(500 * time.Millisecond) app, err := AppClientset.ArgoprojV1alpha1().Applications(TestNamespace()).Get(context.Background(), app.Name, metav1.GetOptions{}) require.NoError(t, err) assert.Empty(t, app.Status.Conditions) @@ -2562,6 +2561,7 @@ func TestDisableManifestGeneration(t *testing.T) { Refresh(RefreshTypeHard). Then(). And(func(app *Application) { + // Wait for refresh to complete time.Sleep(1 * time.Second) }). And(func(app *Application) { diff --git a/test/e2e/applicationset_test.go b/test/e2e/applicationset_test.go index 9ea07939a5e4b..247fc3af2d40a 100644 --- a/test/e2e/applicationset_test.go +++ b/test/e2e/applicationset_test.go @@ -2033,12 +2033,12 @@ func TestSimpleGitFilesPreserveResourcesOnDeletion(t *testing.T) { When(). Delete(). And(func() { - t.Log("Waiting 30 seconds to give the cluster a chance to delete the pods.") - // Wait 30 seconds to give the cluster a chance to deletes the pods, if it is going to do so. + t.Log("Waiting 15 seconds to give the cluster a chance to delete the pods.") + // Wait 15 seconds to give the cluster a chance to deletes the pods, if it is going to do so. // It should NOT delete the pods; to do so would be an ApplicationSet bug, and // that is what we are testing here. - time.Sleep(30 * time.Second) - // The pod should continue to exist after 30 seconds. + time.Sleep(15 * time.Second) + // The pod should continue to exist after 15 seconds. }).Then().Expect(Pod(func(p corev1.Pod) bool { return strings.Contains(p.Name, "guestbook-ui") })) } @@ -2094,12 +2094,12 @@ func TestSimpleGitFilesPreserveResourcesOnDeletionGoTemplate(t *testing.T) { When(). Delete(). And(func() { - t.Log("Waiting 30 seconds to give the cluster a chance to delete the pods.") - // Wait 30 seconds to give the cluster a chance to deletes the pods, if it is going to do so. + t.Log("Waiting 15 seconds to give the cluster a chance to delete the pods.") + // Wait 15 seconds to give the cluster a chance to deletes the pods, if it is going to do so. // It should NOT delete the pods; to do so would be an ApplicationSet bug, and // that is what we are testing here. - time.Sleep(30 * time.Second) - // The pod should continue to exist after 30 seconds. + time.Sleep(15 * time.Second) + // The pod should continue to exist after 15 seconds. }).Then().Expect(Pod(func(p corev1.Pod) bool { return strings.Contains(p.Name, "guestbook-ui") })) } diff --git a/test/e2e/cluster_test.go b/test/e2e/cluster_test.go index db287e83c7737..eab0d49f6aeea 100644 --- a/test/e2e/cluster_test.go +++ b/test/e2e/cluster_test.go @@ -37,7 +37,7 @@ https://kubernetes.default.svc in-cluster %v Successful `, GetVe When(). CreateApp() - tries := 5 + tries := 25 for i := 0; i <= tries; i += 1 { clusterFixture.GivenWithSameState(t). When(). @@ -50,7 +50,7 @@ https://kubernetes.default.svc in-cluster %v Successful `, GetVe break } else if i < tries { // We retry with a simple backoff - time.Sleep(time.Duration(i+1) * time.Second) + time.Sleep(time.Duration(i+1) * 100 * time.Millisecond) } } assert.Equal(t, expected, last) diff --git a/test/e2e/custom_tool_test.go b/test/e2e/custom_tool_test.go index 955a37f975c1b..f9bfc014bb847 100644 --- a/test/e2e/custom_tool_test.go +++ b/test/e2e/custom_tool_test.go @@ -26,7 +26,7 @@ func TestCustomToolWithGitCreds(t *testing.T) { ctx. And(func() { go startCMPServer(t, "./testdata/cmp-gitcreds") - time.Sleep(1 * time.Second) + time.Sleep(100 * time.Millisecond) t.Setenv("ARGOCD_BINARY_NAME", "argocd") }). CustomCACertAdded(). @@ -54,7 +54,7 @@ func TestCustomToolWithGitCredsTemplate(t *testing.T) { ctx. And(func() { go startCMPServer(t, "./testdata/cmp-gitcredstemplate") - time.Sleep(1 * time.Second) + time.Sleep(100 * time.Millisecond) t.Setenv("ARGOCD_BINARY_NAME", "argocd") }). CustomCACertAdded(). @@ -95,7 +95,7 @@ func TestCustomToolWithSSHGitCreds(t *testing.T) { ctx. And(func() { go startCMPServer(t, "./testdata/cmp-gitsshcreds") - time.Sleep(1 * time.Second) + time.Sleep(100 * time.Millisecond) t.Setenv("ARGOCD_BINARY_NAME", "argocd") }). // add the private repo with ssh credentials @@ -129,7 +129,7 @@ func TestCustomToolWithSSHGitCredsDisabled(t *testing.T) { ctx. And(func() { go startCMPServer(t, "./testdata/cmp-gitsshcreds-disable-provide") - time.Sleep(1 * time.Second) + time.Sleep(100 * time.Millisecond) t.Setenv("ARGOCD_BINARY_NAME", "argocd") }). CustomCACertAdded(). @@ -153,7 +153,7 @@ func TestCustomToolWithEnv(t *testing.T) { ctx. And(func() { go startCMPServer(t, "./testdata/cmp-fileName") - time.Sleep(1 * time.Second) + time.Sleep(100 * time.Millisecond) t.Setenv("ARGOCD_BINARY_NAME", "argocd") }). // does not matter what the path is @@ -172,9 +172,6 @@ func TestCustomToolWithEnv(t *testing.T) { Expect(OperationPhaseIs(OperationSucceeded)). Expect(SyncStatusIs(SyncStatusCodeSynced)). Expect(HealthIs(health.HealthStatusHealthy)). - And(func(app *Application) { - time.Sleep(1 * time.Second) - }). And(func(app *Application) { output, err := Run("", "kubectl", "-n", DeploymentNamespace(), "get", "cm", ctx.AppName(), "-o", "jsonpath={.metadata.annotations.Bar}") require.NoError(t, err) @@ -214,7 +211,7 @@ func TestCustomToolSyncAndDiffLocal(t *testing.T) { ctx. And(func() { go startCMPServer(t, "./testdata/cmp-kustomize") - time.Sleep(1 * time.Second) + time.Sleep(100 * time.Millisecond) t.Setenv("ARGOCD_BINARY_NAME", "argocd") }). // does not matter what the path is @@ -226,9 +223,6 @@ func TestCustomToolSyncAndDiffLocal(t *testing.T) { Expect(OperationPhaseIs(OperationSucceeded)). Expect(SyncStatusIs(SyncStatusCodeSynced)). Expect(HealthIs(health.HealthStatusHealthy)). - And(func(app *Application) { - time.Sleep(1 * time.Second) - }). And(func(app *Application) { FailOnErr(RunCli("app", "sync", ctx.AppName(), "--local", appPath, "--local-repo-root", testdataPath)) }). @@ -257,7 +251,7 @@ func TestCMPDiscoverWithFileName(t *testing.T) { Given(t). And(func() { go startCMPServer(t, "./testdata/cmp-fileName") - time.Sleep(1 * time.Second) + time.Sleep(100 * time.Millisecond) t.Setenv("ARGOCD_BINARY_NAME", "argocd") }). Path(pluginName + "/subdir"). @@ -275,7 +269,7 @@ func TestCMPDiscoverWithFindGlob(t *testing.T) { Given(t). And(func() { go startCMPServer(t, "./testdata/cmp-find-glob") - time.Sleep(1 * time.Second) + time.Sleep(100 * time.Millisecond) t.Setenv("ARGOCD_BINARY_NAME", "argocd") }). Path("guestbook"). @@ -293,7 +287,7 @@ func TestCMPDiscoverWithPluginName(t *testing.T) { Given(t). And(func() { go startCMPServer(t, "./testdata/cmp-find-glob") - time.Sleep(1 * time.Second) + time.Sleep(100 * time.Millisecond) t.Setenv("ARGOCD_BINARY_NAME", "argocd") }). Path("guestbook"). @@ -316,7 +310,7 @@ func TestCMPDiscoverWithFindCommandWithEnv(t *testing.T) { ctx. And(func() { go startCMPServer(t, "./testdata/cmp-find-command") - time.Sleep(1 * time.Second) + time.Sleep(100 * time.Millisecond) t.Setenv("ARGOCD_BINARY_NAME", "argocd") }). Path(pluginName). @@ -327,9 +321,6 @@ func TestCMPDiscoverWithFindCommandWithEnv(t *testing.T) { Expect(OperationPhaseIs(OperationSucceeded)). Expect(SyncStatusIs(SyncStatusCodeSynced)). Expect(HealthIs(health.HealthStatusHealthy)). - And(func(app *Application) { - time.Sleep(1 * time.Second) - }). And(func(app *Application) { output, err := Run("", "kubectl", "-n", DeploymentNamespace(), "get", "cm", ctx.AppName(), "-o", "jsonpath={.metadata.annotations.Bar}") require.NoError(t, err) @@ -359,7 +350,7 @@ func TestPruneResourceFromCMP(t *testing.T) { Given(t). And(func() { go startCMPServer(t, "./testdata/cmp-find-glob") - time.Sleep(1 * time.Second) + time.Sleep(100 * time.Millisecond) t.Setenv("ARGOCD_BINARY_NAME", "argocd") }). Path("guestbook"). @@ -382,7 +373,7 @@ func TestPreserveFileModeForCMP(t *testing.T) { Given(t). And(func() { go startCMPServer(t, "./testdata/cmp-preserve-file-mode") - time.Sleep(1 * time.Second) + time.Sleep(100 * time.Millisecond) t.Setenv("ARGOCD_BINARY_NAME", "argocd") }). Path("cmp-preserve-file-mode"). @@ -402,7 +393,7 @@ func TestCMPWithSymlinkPartialFiles(t *testing.T) { Given(t, WithTestData("testdata2")). And(func() { go startCMPServer(t, "./testdata2/cmp-symlink") - time.Sleep(1 * time.Second) + time.Sleep(100 * time.Millisecond) t.Setenv("ARGOCD_BINARY_NAME", "argocd") }). Path("guestbook-partial-symlink-files"). @@ -419,7 +410,7 @@ func TestCMPWithSymlinkFiles(t *testing.T) { Given(t, WithTestData("testdata2")). And(func() { go startCMPServer(t, "./testdata2/cmp-symlink") - time.Sleep(1 * time.Second) + time.Sleep(100 * time.Millisecond) t.Setenv("ARGOCD_BINARY_NAME", "argocd") }). Path("guestbook-symlink-files"). @@ -436,7 +427,7 @@ func TestCMPWithSymlinkFolder(t *testing.T) { Given(t, WithTestData("testdata2")). And(func() { go startCMPServer(t, "./testdata2/cmp-symlink") - time.Sleep(1 * time.Second) + time.Sleep(100 * time.Millisecond) t.Setenv("ARGOCD_BINARY_NAME", "argocd") }). Path("guestbook-symlink-folder"). diff --git a/test/e2e/fixture/applicationsets/utils/fixture.go b/test/e2e/fixture/applicationsets/utils/fixture.go index bd8d035018d71..21134caa2bd20 100644 --- a/test/e2e/fixture/applicationsets/utils/fixture.go +++ b/test/e2e/fixture/applicationsets/utils/fixture.go @@ -278,6 +278,18 @@ func cleanUpNamespace(fixtureClient *E2EFixtureK8sClient, namespace string) erro func waitForSuccess(condition func() error, expireTime time.Time) error { var mostRecentError error + sleepIntervals := []time.Duration{ + 10 * time.Millisecond, + 20 * time.Millisecond, + 50 * time.Millisecond, + 100 * time.Millisecond, + 200 * time.Millisecond, + 300 * time.Millisecond, + 500 * time.Millisecond, + 1 * time.Second, + } + sleepIntervalsIdx := -1 + for { if time.Now().After(expireTime) { break @@ -293,8 +305,11 @@ func waitForSuccess(condition func() error, expireTime time.Time) error { break } - // Wait 0.5 seconds on fail - time.Sleep(500 * time.Millisecond) + // Wait on fail + if sleepIntervalsIdx < len(sleepIntervals)-1 { + sleepIntervalsIdx++ + } + time.Sleep(sleepIntervals[sleepIntervalsIdx]) } return mostRecentError } diff --git a/test/e2e/fixture/fixture.go b/test/e2e/fixture/fixture.go index 2709917c53561..7de7448257164 100644 --- a/test/e2e/fixture/fixture.go +++ b/test/e2e/fixture/fixture.go @@ -1011,7 +1011,7 @@ func RestartRepoServer() { FailOnErr(Run("", "kubectl", "rollout", "-n", TestNamespace(), "restart", "deployment", workload)) FailOnErr(Run("", "kubectl", "rollout", "-n", TestNamespace(), "status", "deployment", workload)) // wait longer to avoid error on s390x - time.Sleep(10 * time.Second) + time.Sleep(5 * time.Second) } } diff --git a/test/e2e/hook_test.go b/test/e2e/hook_test.go index f69fc18defcc5..a538566986213 100644 --- a/test/e2e/hook_test.go +++ b/test/e2e/hook_test.go @@ -335,7 +335,7 @@ func TestHookBeforeHookCreation(t *testing.T) { CheckError(err) assert.NotEmpty(t, creationTimestamp1) // pause to ensure that timestamp will change - time.Sleep(2 * time.Second) + time.Sleep(1 * time.Second) }). When(). Sync(). diff --git a/test/e2e/project_management_test.go b/test/e2e/project_management_test.go index 4222577fa3fc0..169227eea52a5 100644 --- a/test/e2e/project_management_test.go +++ b/test/e2e/project_management_test.go @@ -533,10 +533,6 @@ func TestGetVirtualProjectNoMatch(t *testing.T) { "--path", guestbookPath, "--project", proj.Name, "--dest-server", v1alpha1.KubernetesInternalAPIServerAddr, "--dest-namespace", fixture.DeploymentNamespace()) require.NoError(t, err) - // Waiting for the app to be successfully created. - // Else the sync would fail to retrieve the app resources. - time.Sleep(time.Second * 2) - // App trying to sync a resource which is not blacked listed anywhere _, err = fixture.RunCli("app", "sync", fixture.Name(), "--resource", "apps:Deployment:guestbook-ui", "--timeout", strconv.Itoa(10)) require.NoError(t, err) @@ -573,10 +569,6 @@ func TestGetVirtualProjectMatch(t *testing.T) { "--path", guestbookPath, "--project", proj.Name, "--dest-server", v1alpha1.KubernetesInternalAPIServerAddr, "--dest-namespace", fixture.DeploymentNamespace()) require.NoError(t, err) - // Waiting for the app to be successfully created. - // Else the sync would fail to retrieve the app resources. - time.Sleep(time.Second * 2) - // App trying to sync a resource which is not blacked listed anywhere _, err = fixture.RunCli("app", "sync", fixture.Name(), "--resource", "apps:Deployment:guestbook-ui", "--timeout", strconv.Itoa(10)) require.ErrorContains(t, err, "blocked by sync window")