test(flaky): fix paramter type assert in testBothAnnotatedConstructor test case #5751
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
The
testBothAnnotatedConstructor
test inCachedConstructorAnalyzerTest
fails randomly because constructor selection is non-deterministic when multiple constructors have the same number of parameters. Specifically,BothAnnotatedConstructor
has two single-parameter constructors: one accepting a String and the other an Integer. SincegetDeclaredConstructors
does not guarantee order, the test may select either constructor, leading to intermittent failures.Fix
Adjust the test to validate that the parameter type of the returned constructor is either
String
orInteger
, accommodating both possible outcomes.How Has This Been Tested
Identified this test to be flaky using NonDex tool (which explores different behaviors of under-determined APIs and reports test failures). Here are the commands to run this test case with NonDex tool
Here is the screenshot of the output generated by the NonDex tool
In the above case, we can see that the test case fails intermittently, in the first instance it passed successfully, however in the second instance it failed with error
CachedConstructorAnalyzerTest.testBothAnnotatedConstructor:113 expected: <java.lang.Integer> but was: <java.lang.String>