Skip to content

Commit

Permalink
chore: Remove or reduce sleep in e2e tests (#21010)
Browse files Browse the repository at this point in the history
Closes #21009

Some sleeps may no longer be necessary or be too long. Try removing or reducing duration.

Signed-off-by: Andrii Korotkov <[email protected]>
Co-authored-by: Michael Crenshaw <[email protected]>
  • Loading branch information
andrii-korotkov-verkada and crenshaw-dev authored Dec 2, 2024
1 parent c06974f commit 5fc306e
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 49 deletions.
3 changes: 1 addition & 2 deletions test/e2e/app_management_ns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -2439,14 +2438,14 @@ func TestNamespacedDisableManifestGeneration(t *testing.T) {
}).
When().
And(func() {
time.Sleep(3 * time.Second)
SetEnableManifestGeneration(map[ApplicationSourceType]bool{
ApplicationSourceTypeKustomize: false,
})
}).
Refresh(RefreshTypeHard).
Then().
And(func(app *Application) {
// Wait for refresh to complete
time.Sleep(1 * time.Second)
}).
And(func(app *Application) {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 8 additions & 8 deletions test/e2e/applicationset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") }))
}

Expand Down Expand Up @@ -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") }))
}

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand All @@ -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)
Expand Down
39 changes: 15 additions & 24 deletions test/e2e/custom_tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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().
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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))
}).
Expand Down Expand Up @@ -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").
Expand All @@ -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").
Expand All @@ -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").
Expand All @@ -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).
Expand All @@ -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)
Expand Down Expand Up @@ -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").
Expand All @@ -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").
Expand All @@ -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").
Expand All @@ -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").
Expand All @@ -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").
Expand Down
19 changes: 17 additions & 2 deletions test/e2e/fixture/applicationsets/utils/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/fixture/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
8 changes: 0 additions & 8 deletions test/e2e/project_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 5fc306e

Please sign in to comment.