Skip to content
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

test(flaky): fix paramter type assert in testBothAnnotatedConstructor test case #5751

Merged
merged 2 commits into from
Oct 3, 2024

Conversation

varsha-cl
Copy link
Contributor

Description

The testBothAnnotatedConstructor test in CachedConstructorAnalyzerTest 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. Since getDeclaredConstructors 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 or Integer, 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

# Install the dependencies
mvn install -pl incubator/cdi-inject-weld -am -DskipTests

# Run the test with NonDex
mvn -pl incubator/cdi-inject-weld \
    edu.illinois:nondex-maven-plugin:2.1.7:nondex \
    -Dtest=org.glassfish.jersey.inject.weld.internal.injector.CachedConstructorAnalyzerTest#testBothAnnotatedConstructor

Here is the screenshot of the output generated by the NonDex tool
Screenshot 2024-09-02 at 12 05 07 PM

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>

@varsha-cl varsha-cl force-pushed the fix-annotated-constructor-test branch from 050166b to 9832ee1 Compare September 30, 2024 18:18
@jansupol
Copy link
Contributor

jansupol commented Oct 2, 2024

@varsha-cl This looks correct. While we are not seeing this issue, I assume it can occur.

This is the same as in the other CachedConstructorAnalyzerTest test (yes, we duplicate the test in the incubator module because of its immaturity for the time being) which should be updated the same way.

The copyright year needs to be updated to 2024 before this PR's tests pass.

@varsha-cl
Copy link
Contributor Author

@varsha-cl This looks correct. While we are not seeing this issue, I assume it can occur.

This is the same as in the other CachedConstructorAnalyzerTest test (yes, we duplicate the test in the incubator module because of its immaturity for the time being) which should be updated the same way.

The copyright year needs to be updated to 2024 before this PR's tests pass.

Thank you the feedback. I have updated the year and replicated the changes in other test file as well

@senivam senivam merged commit ef6418c into eclipse-ee4j:2.x Oct 3, 2024
6 of 7 checks passed
@senivam senivam added this to the 2.46 milestone Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants