Fix flaky UnresolvedNamePatternTests equals check#143191
Fix flaky UnresolvedNamePatternTests equals check#143191ebarlas wants to merge 2 commits intoelastic:mainfrom
Conversation
|
Pinging @elastic/es-analytical-engine (Team:Analytics) |
alex-spies
left a comment
There was a problem hiding this comment.
Thanks a lot @ebarlas , you've uncovered an old hidden trap.
It needs fixing more than the test, though. I'll open a separate PR with a proposed fix and plan to absorb your test fix into it if that's ok.
| switch (between(0, 1)) { | ||
| case 0 -> name = randomValueOtherThan(name, () -> randomAlphaOfLength(4)); | ||
| case 1 -> pattern = randomValueOtherThan(pattern, () -> randomAlphaOfLength(4)); | ||
| String pattern = randomValueOtherThan(instance.pattern(), () -> randomAlphaOfLength(4)); |
There was a problem hiding this comment.
This doesn't follow the normal pattern of "retrieve all relevant instance attributes, randomly mutated one". The pattern is always mutated. We need to test the case when the pattern stays the same and only the name is mutated.
Changing just the name should lead to inequality. I think this PR uncovered a genuine bug in UnresolvedNamePattern that needs fixing instead.
| name = randomValueOtherThan(name, () -> randomAlphaOfLength(4)); | ||
| } | ||
| return new UnresolvedNamePattern(source, null, name, pattern); | ||
| return new UnresolvedNamePattern(source, null, pattern, name); |
There was a problem hiding this comment.
Swapping the arguments is a correct test fix. We should only merge this part and leave the mutation logic as it was before.
Thanks @ebarlas for the find! Supersedes #143191. * Fix `UnresolvedNamePatternTests` by actually ensuring that the equality is sensitive to changes of the `name`. * Fix `UnresolvedNamePattern#equals` and `#hashCode` to account for differences in the `name` We probably never saw problems from this in production because the name is derived from the pattern. Basic equality methods should still work correctly, however.
Thanks @ebarlas for the find! Supersedes elastic#143191. * Fix `UnresolvedNamePatternTests` by actually ensuring that the equality is sensitive to changes of the `name`. * Fix `UnresolvedNamePattern#equals` and `#hashCode` to account for differences in the `name` We probably never saw problems from this in production because the name is derived from the pattern. Basic equality methods should still work correctly, however.
Thanks @ebarlas for the find! Supersedes #143191. * Fix `UnresolvedNamePatternTests` by actually ensuring that the equality is sensitive to changes of the `name`. * Fix `UnresolvedNamePattern#equals` and `#hashCode` to account for differences in the `name` We probably never saw problems from this in production because the name is derived from the pattern. Basic equality methods should still work correctly, however.
Thanks @ebarlas for the find! Supersedes elastic#143191. * Fix `UnresolvedNamePatternTests` by actually ensuring that the equality is sensitive to changes of the `name`. * Fix `UnresolvedNamePattern#equals` and `#hashCode` to account for differences in the `name` We probably never saw problems from this in production because the name is derived from the pattern. Basic equality methods should still work correctly, however.
UnresolvedNamePatternTests.mutateInstancehad two bugs:Swapped constructor arguments — the constructor takes
(source, automaton, patternString, name)butmutateInstancepassed(source, null, name, pattern), swapping the two. This was masked when name and pattern differed (the common case).Mutating a non-equality field —
case 0only mutatedname, butUnresolvedNamePattern.innerEqualsonly checkspattern. Thenamefield is invisible to equality becauseUnresolvedNamedExpressionpasses"<unresolved>"as the superclassnametoNamedExpression, and the overriddenname()return value is never checked. When the random instance happened to generate the same value for bothnameandpattern, the swap became visible andcase 1produced a mutation with the samepatternas the original.The fix ensures
patternis always mutated (guaranteeing inequality) and corrects the constructor argument order.Reproduces with: