fix flaky tests #4
Open
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
Fixed the flaky test
extendedXmlJavaTypeAdapterandsimpleXmlJavaTypeAdapterinsideJAXBUtilsTest.javaclass.cxf/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXBUtilsTest.java
Line 38 in 1a02ba3
cxf/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXBUtilsTest.java
Line 43 in 1a02ba3
Root Cause
The tests
extendedXmlJavaTypeAdapterandsimpleXmlJavaTypeAdapterhave been reported flaky when run with the NonDex tool. The tests failed due to the non-deterministic ordering of fields returned by getDeclaredFields(). The getDeclaredFields() method returns an array of Field objects representing all the fields declared by a class or interface. In the above tests, it returned two values: one a private field named birthDate of typejava.time.LocalDateand the otherorg.apache.cxf.jaxrs.utils.JAXBUtilsTest$CustomerDetailsWithExtendedAdapter.this$0. The second value represents a synthetic field generated by the Java compiler for the inner class CustomerDetailsWithExtendedAdapter. When an inner class accesses members of its enclosing class, Java creates a synthetic field (in this case, this$0) as a reference to the outer class (JAXBUtilsTest) which is not useful for the test.Fix
To ensure the tests are not flaky due to the non-deterministic ordering of fields returned by getDeclaredFields(), we introduced a condition to filter out the fields(synthetic and final fields) that are not useful for the testing.
How this has been tested?
Java: openjdk version "17.0.8"
Maven: Apache Maven 3.6.3
Command used -
Commands used -
Command used -
NonDex test passed after the fix.