-
Notifications
You must be signed in to change notification settings - Fork 591
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
Fix inconsistent route order test flake in TestParserSNI
#4777
Conversation
Use a consistent order for the routes attached to a service in the parser. This makes tests that care about the route index not flaky.
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4777 +/- ##
=====================================
Coverage 77.7% 77.7%
=====================================
Files 163 164 +1
Lines 18541 18561 +20
=====================================
+ Hits 14409 14436 +27
+ Misses 3322 3316 -6
+ Partials 810 809 -1
☔ View full report in Codecov by Sentry. |
9f4beaa
to
b6e6b7b
Compare
b6e6b7b
to
e0a4a84
Compare
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.
IMO it would be better to modify the unit tests (like finding the target route using lo.ContainsBy
) instead of changing the parser to fix the order of routes if we do not have other reasons to have a fixed route order.
I have created #4781 which changes the tests instead of the code which creates the service routes. One thing though, which is on my mind, is that perhaps we should actually do it as proposed in here because that might reduce sending unnecessary configuration change requests to Gateway, right? If we change it in tests then more requests could be sent because the order of service routes could change from parser run to parser run even though the underlying objects didn't change. |
// the order of routes ultimately doesn't matter, but using a consistent order simplifies unit testing, | ||
// as the output only has array indices and cannot be accessed by name |
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.
That comment might not be 100% accurate because the order ultimately does matter when we want to figure out if the config is different than the one were going to overwrite (in Admin API) right?
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 believe sorting is handled in another layer - deckgen.ToDeckContent
sorts all the entities:
func ToDeckContent( |
I think it's okay to stick to that and leave the parser to return non-deterministically ordered slices.
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.
Cool. In that case we could add a comment mentioning this explicitly. And just leave it as it. Would this mean that we can move forward with #4781 ?
package util | ||
|
||
// StringHeap is an array of strings that implements container/heap.Interface. | ||
type StringHeap []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.
Would it be difficult to make the heap contain the ingressTranslationMeta
(just as in the map
) to prevent having both map
and heap
inside the ingressTranslationIndex
?
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 tried as much and got sad discovering that this didn't really slot neatly into the simple data structure :) We have to modify the entries as we go to add new paths, and we find the correct entry to modify based on the key, so we basically end up with some combination of a map and a heap to manage that, sooooo...
TestParserSNI
Pull request was closed
What this PR does / why we need it:
Use a consistent order for the routes attached to a service in the parser. This makes tests that care about the route index not flaky.
Which issue this PR fixes:
TestParserSNI began failing recently, e.g. https:/Kong/kubernetes-ingress-controller/actions/runs/6407581302/job/17394681361
The origin of the flake isn't clear, but 23de4f5 seems the most likely candidate for introducing it based on date and affected code.
Special notes for your reviewer:
This is, oddly enough, the only parser test that uses multiple indices. We could alternately look up the routes by name for this test and not change anything in the translator. IDK how likely we'd be to add other affected tests in the future, or how much we'd care about the small bit of essentially wasted CPU time to avoid it.
PR Readiness Checklist:
Complete these before marking the PR as
ready to review
:theonly fixes tests for an unreleased changeCHANGELOG.md
release notes have been updated to reflect any significant (and particularly user-facing) changes introduced by this PR