Skip to content
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

🌱 Flakes: replace require with assert in retry funcs #1330

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

m1kola
Copy link
Member

@m1kola m1kola commented Oct 3, 2024

Description

When require assertions are not satisfied they fails a test immediately. This is not desired when used
with retry function such as EventuallyWithT since they are supposed to retry on a failure.

This can cause flakes when, for example, we are asserting on a resource condition. On the first hit the resource might not have a condition and require will fail EventuallyWithT despite the fact that the code is correct and the condition gets set eventually.

Example failures from today & yesterday:

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

When `require` assertions are not satisfied they fails
a test immediately. This is not desired when used
with retry function such as `EventuallyWithT` since
they are supposed to retry on a failure.

This can cause flakes when, for example, we are asserting
on a resource condition. On the first hit the resource might
not have a condition and `require` will fail `EventuallyWithT`
despite the fact that the code is correct and the condition
gets set eventually.

Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
@m1kola m1kola requested a review from a team as a code owner October 3, 2024 12:52
Copy link

netlify bot commented Oct 3, 2024

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit 4af861e
🔍 Latest deploy log https://app.netlify.com/sites/olmv1/deploys/66fe9379c64ce0000830c03d
😎 Deploy Preview https://deploy-preview-1330--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@m1kola m1kola changed the title 🌱 Replace require with assert in retry funcs 🌱 Flakes: replace require with assert in retry funcs Oct 3, 2024
Copy link

codecov bot commented Oct 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.13%. Comparing base (801388a) to head (4af861e).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1330      +/-   ##
==========================================
- Coverage   76.17%   76.13%   -0.05%     
==========================================
  Files          41       41              
  Lines        2409     2409              
==========================================
- Hits         1835     1834       -1     
- Misses        401      402       +1     
  Partials      173      173              
Flag Coverage Δ
e2e 58.32% <ø> (ø)
unit 53.13% <ø> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@grokspawn
Copy link
Contributor

Can we generalize the statement that we should not use require in Eventually expressions?

I know this is just test code, but the extra lines are messing with my OCD. 😉
Would it flow better to do something like (example from these lines):

		require.EventuallyWithT(t, func(ct *assert.CollectT) {
				assert.NoError(ct, c.Get(context.Background(), types.NamespacedName{Name: clusterExtension.Name}, clusterExtension))
				cond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1alpha1.TypeProgressing)
				if assert.NotNil(ct, cond) {
				   assert.Equal(ct, metav1.ConditionFalse, cond.Status)
   				   assert.Equal(ct, ocv1alpha1.ReasonSuccess, cond.Reason)
				}
			}, pollDuration, pollInterval)

@grokspawn grokspawn added this pull request to the merge queue Oct 3, 2024
Merged via the queue into operator-framework:main with commit ab99642 Oct 3, 2024
17 of 18 checks passed
@m1kola m1kola deleted the fix_eventually_asserts branch October 3, 2024 15:32
m1kola pushed a commit to grokspawn/operator-controller that referenced this pull request Oct 4, 2024
While reviewing operator-framework#1330
we had a discussion about the ability to generally prevent the use of `requires`
within `Eventually` calls to prevent future flakes, and that led us to evaluate
the `testifylint`-er to give us some cautionary guidelines.

It did _not_ resolve the requires-within-eventually issue,
but we may try to tackle that with some custom AST in the future.

Signed-off-by: Jordan Keister <jordan@nimblewidget.com>
github-merge-queue bot pushed a commit that referenced this pull request Oct 4, 2024
While reviewing #1330
we had a discussion about the ability to generally prevent the use of `requires`
within `Eventually` calls to prevent future flakes, and that led us to evaluate
the `testifylint`-er to give us some cautionary guidelines.

It did _not_ resolve the requires-within-eventually issue,
but we may try to tackle that with some custom AST in the future.

Signed-off-by: Jordan Keister <jordan@nimblewidget.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants