-
Notifications
You must be signed in to change notification settings - Fork 97
🌱 Fix flaky unit-tests 🎉🎉🎉 #1723
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
Conversation
Before the test did not realy test something because the state is none at the beginning (before provisioning), too.
janiskemper
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.
the test doesn't test deletion anymore, but deprovisioning of the host when a hetznerbaremetalmachine is deleted. Can you explain why you change the test? Also, if you wanna do that change, you should update the test description
Background: All tests share the same reconciler and mock objects. This means if test-1 changes the mocks, then test-2 could fail. The method CreateNamespace() was changed to ResetAndCreateNamespace(). Flakiness should be reduced, because every test resets the mocks now.
use hack/filter-caph-controller-manager-logs.py to filter noise.
|
I don't think it is a good idea to change the base branch.. Do you want to merge it to the other one? |
I need the changes from the other branch to see the output of test failures clearly. I hope the other branch gets approved and merged soon. Then this PR goes into main. |
janiskemper
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.
well the last change of the base branch dismissed my review ;)
Before this PR roughly 3 of 10
make test-unitcalls failed because of a flaky test. Many tests already contained the string "(flaky)" in the name.The root-cause is that mocks and reconcilers are shared between tests.
All tests run sequentially (no concurrency). But changes done in one test could influence the second test.
Running tests in isolation (for example via
FIt()) always succeeded.This PR updates CreateNamespace() to ResetAndCreateNamespace().
Mocks get re-created via a Reset() method.
On my local device the tests were successful 70 times in a row (still running).
Introduces a Resetter/ResetAndCreateNamespace pattern for tests, to:
Resetting alone did not remove the flakiness. This PR ensures that mocks which have a state (like HCloudClient) do not get used, when a test has finished.
The background is explained in the kubebuilder docs: envTest, Namespace usage Limitations: Namespaces can't be deleted in envTests. This means objects from test-1 might still exist and getting reconciled while test-2 runs. When test-1 uses the stateful hcloudClient, although this test has already passed, it modifies the environment of test-2. Resetting does not resolve this.
This PR uses the pattern suggested by the kubebuilder docs: FooReconciler.Namespace. At the top of the Reconcile method the namespace gets checked. If set and different, reconcile is stopped.
The test for hbmm deletion was updated. It checks that the host gets deprovisioned. And the same test gets done in phase "ensure-provisioned".
HetznerBareMetalHostReconciler in "avoid conflict errors": Ignore NotFound error.
Closes #1685 #1506 #1435