Fix improper use of non-polling Eventually in tests#1
Open
vzdai wants to merge 5 commits intofallback-validationfrom
Open
Fix improper use of non-polling Eventually in tests#1vzdai wants to merge 5 commits intofallback-validationfrom
vzdai wants to merge 5 commits intofallback-validationfrom
Conversation
…plica counts Signed-off-by: Vivian Dai <viviandai12@gmail.com>
Signed-off-by: Vivian Dai <viviandai12@gmail.com>
Signed-off-by: Vivian Dai <viviandai12@gmail.com>
Signed-off-by: Vivian Dai <viviandai12@gmail.com>
Signed-off-by: Vivian Dai <viviandai12@gmail.com>
vzdai
commented
Aug 13, 2024
| }).ShouldNot(HaveOccurred()) | ||
| }) | ||
|
|
||
| var _ = It("shouldn't create so when stabilizationWindowSeconds exceeds 3600", func() { |
Owner
Author
There was a problem hiding this comment.
Validation for stabilizationWindowSeconds was added in kedacore#4983 via a validation patch directly on the CRD. It looks like the patch doesn't get picked up by the admission webhook, so the webhook actually thinks this is a valid object. This test is a false positive, and I don't think it belongs in this file with the rest of the admission webhook unit tests.
# error message when rejected by admission webhook
Error from server (Forbidden): error when creating "scaledobject.yaml": admission webhook "vscaledobject.kb.io" denied the request: type is cpu , but fallback it is not supported by the CPU & memory scalers
# error message when rejected by CRD validation
The ScaledObject "keda-test" is invalid: spec.advanced.horizontalPodAutoscalerConfig.behavior.scaleDown.stabilizationWindowSeconds: Invalid value: 36000: spec.advanced.horizontalPodAutoscalerConfig.behavior.scaleDown.stabilizationWindowSeconds in body should be less than or equal to 3600
I'm not sure how to test a direct CRD patch though so I haven't added a replacement test - need to look into it more, or open to suggestions here.
ce73bea to
32ff796
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
As discovered in kedacore#5962 (comment), the
Eventuallyfunction of Gomega is meant toblock when called and attempts an assertion periodically until it passes or a timeout occurs(docs).This means we should be using it with polling functions such as
Getto wait for an event to happen (example), but not functions such asCreateunless we're intending to repeatedly try the creation until something different happens.Our incorrect usage causes the existing tests to report false results, because in cases such as:
An error does occur here, but that's caused by the error
resourceVersion should not be set on objects to be createdsincesogets modified in-place after the first create and we're trying to apply it again.On the other hand, if we expect no error to occur with the create:
If the first
Createpasses, then the Eventually block also passes. In this case, there's no point having theEventuallysince we're not waiting for anything.Changes
As proof that this
Eventuallyis not necessary and will only lead to false positives, I've tried removing the wrapper from all places where it's called with a mutatingCreateorUpdatecall. With this change, the tests still pass.Checklist
Fixes #
Relates to #