Skip to content

Fix flaky e2e test #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Fix flaky e2e test #370

wants to merge 1 commit into from

Conversation

slintes
Copy link
Member

@slintes slintes commented Jun 22, 2025

Why we need this PR

Sometimes cleanup in e2e test fails due to API errors, which fails the next test as well.

Changes made

Retry the delete command, and wait until the resource is gone.

Summary by CodeRabbit

  • Tests
    • Improved the cleanup process in end-to-end tests to ensure more reliable and timely deletion of test objects.

Copy link

coderabbitai bot commented Jun 22, 2025

Walkthrough

The cleanup logic in the end-to-end test suite was refactored. Instead of a single deferred cleanup function deleting all objects sequentially with fixed delays, a single deferred cleanup still exists but now deletes objects in reverse order using asynchronous retries and verification with timeouts, replacing synchronous deletion with sleeps. Object creation also now waits for successful retrieval using retries instead of fixed sleeps.

Changes

File(s) Change Summary
e2e/e2e_suite_test.go Refactored setup and cleanup: reversed deletion order; replaced synchronous sleeps with asynchronous retries and verification using Eventually assertions for both creation and deletion of Kubernetes objects.

Poem

A rabbit hops through code so neat,
Cleaning up after every feat.
Now backwards it goes, with patience and care,
Checking each step with time to spare.
No more waits that stall the run,
Cleanup done swiftly—hopping’s fun! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9c354c3 and b6769aa.

📒 Files selected for processing (1)
  • e2e/e2e_suite_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • e2e/e2e_suite_test.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: e2e-k8s
  • GitHub Check: build-and-unit-test
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@openshift-ci openshift-ci bot requested review from beekhof and mshitrit June 22, 2025 11:50
Copy link
Contributor

openshift-ci bot commented Jun 22, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: slintes

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@slintes
Copy link
Member Author

slintes commented Jun 22, 2025

/cherry-pick release-0.9

@openshift-cherrypick-robot

@slintes: once the present PR merges, I will cherry-pick it on top of release-0.9 in a new PR and assign it to you.

In response to this:

/cherry-pick release-0.9

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
e2e/e2e_suite_test.go (1)

169-177: Excellent approach to fix flaky cleanup, but consider handling already-deleted objects.

The refactored cleanup logic properly addresses the flaky test issue by using individual deferred cleanup functions with retry logic. The two-phase approach (delete + verify) ensures reliable cleanup.

However, consider handling the case where objects might already be deleted:

 DeferCleanup(func() {
 	Eventually(func(g Gomega) {
-		g.Expect(k8sClient.Delete(context.Background(), obj)).To(Succeed())
+		err := k8sClient.Delete(context.Background(), obj)
+		g.Expect(err).To(Or(Succeed(), MatchError(ContainSubstring("not found"))))
 	}, 1*time.Minute, 5*time.Second).Should(Succeed())
 	Eventually(func(g Gomega) {
 		err := k8sClient.Get(context.Background(), ctrl.ObjectKeyFromObject(obj), obj)
 		g.Expect(errors.IsNotFound(err)).To(BeTrue())
 	}, 1*time.Minute, 5*time.Second).Should(Succeed())
 })

This prevents cleanup failures when objects are already deleted, making the tests more robust.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f7f2c1d and 48678b4.

📒 Files selected for processing (1)
  • e2e/e2e_suite_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: e2e-k8s
  • GitHub Check: build-and-unit-test

@slintes
Copy link
Member Author

slintes commented Jun 22, 2025

/retest

Sometimes cleanup fails due to API errors, which fails the next test
as well. So retry the delete command, and wait until
the resource is gone.

Signed-off-by: Marc Sluiter <[email protected]>
Copy link
Contributor

openshift-ci bot commented Jun 22, 2025

@slintes: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/4.18-openshift-e2e b6769aa link true /test 4.18-openshift-e2e

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Copy link
Contributor

@clobrano clobrano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a minor comment

}
DeferCleanup(func() {
// cleanup in reverse order!
for _, obj := range []ctrl.Object{clusterRole, dummyTemplate, dummyCRD, dummyTemplateCRD} {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we reverse the original list programmatically? This way there will only be one copy, and we should avoid bugs if the list changes in the future.

Expect(k8sClient.Delete(context.Background(), obj)).To(Succeed())
time.Sleep(1 * time.Second)
}
})
for _, obj := range []ctrl.Object{dummyTemplateCRD, dummyCRD, dummyTemplate, clusterRole} {
Expect(k8sClient.Create(context.Background(), obj)).To(Succeed())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think it would be nicer to add the cleanup here as a function.
i.e something like:

Expect(k8sClient.Create(context.Background(), obj)).To(Succeed())
DeferCleanup(cleanUpObj, obj)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, because "// cleanup in reverse order!"
the CR must be cleaned up before the corresponding CRD

Copy link
Member

@mshitrit mshitrit Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be executed in a reverse order, because Defer are stacked and not queued.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, I got an error like "unknown kind" before I switched to how it's done now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my best guess is that wrong obj was passed to the cleanup (i.e all cleanups got the same ref).
I vaguely remember go being tricky that way, if that's the case it's an easy fix.

Feel free to explore further or leave as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants