-
Notifications
You must be signed in to change notification settings - Fork 54
ROX-30138: Add tests for WithSelector #496
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
base: main
Are you sure you want to change the base?
ROX-30138: Add tests for WithSelector #496
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #496 +/- ##
===========================================
- Coverage 85.06% 74.71% -10.35%
===========================================
Files 19 31 +12
Lines 1346 2037 +691
===========================================
+ Hits 1145 1522 +377
- Misses 125 433 +308
- Partials 76 82 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
porridge
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is much better than the previous one, and it will actually fail when we accidentally stop passing the predicate, so it's useful.
However, I'm afraid that this test passing does not guarantee much. AFAICT there is no way to be sure whether the controller will never schedule the unwanted CR for reconciliation, or if it just did not get round to doing that yet. 🤔
Perhaps we can improve our confidence a bit by creating the unlabeled CR before the labeled one?
| controllerName := fmt.Sprintf("%v-controller", strings.ToLower(gvk.Kind)) | ||
| Expect(r.addDefaults(mgr, controllerName)).To(Succeed()) | ||
| r.setupScheme(mgr) | ||
|
|
||
| c, err := controller.New(controllerName, mgr, controller.Options{ | ||
| Reconciler: reconciler, | ||
| MaxConcurrentReconciles: 1, | ||
| }) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
| Expect(r.setupWatches(mgr, c)).To(Succeed()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This duplicates a bunch of code from SetupWithManager. I don't think we should be doing this, it makes the test brittle. I guess the reason is that you want to append to reconciledCRs? Perhaps consider using a hook for this instead?
| By("verifying the previously unlabeled CR was reconciled after label change", func() { | ||
| reconciledCRsMutex.Lock() | ||
| defer reconciledCRsMutex.Unlock() | ||
| Expect(reconciledCRs).To(ContainElement(unlabeledObjKey.String())) | ||
| }) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think once the above By passes, this one is superfluous, since it checks the same thing?
| Eventually(func() []string { | ||
| reconciledCRsMutex.Lock() | ||
| defer reconciledCRsMutex.Unlock() | ||
| return reconciledCRs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that since this returns a slice pointing at the same backing array, the caller will race with other accesses 🤔
Perhaps instead check the existence of desired element in the Eventually, in the scope of the lock, and then make Should just check for true return value?
Co-authored-by: Marcin Owsiany <[email protected]>
Follow up for #459
Add test for
WithSelectorusing controller manager to emulate reconcile lifecycle