yijut2 opened a new pull request, #1528:
URL: https://github.com/apache/cxf/pull/1528
**Description**
Fixed the order dependent flaky test in AttachmentUtilTest.java in core
module.
**Root Cause**
The polluter that caused the flakiness in `AttachmentUtilTest.java` was the
test class `CachedOutputStreamTest.java`. In `AttachmentUtilTest`, there were
multiple tests that used Mockito.spy() to verify the behavior of
`CachedOutputStream` object. In those tests, the spy `CachedOutputStream`
object "cos" was generated (`CachedOutputStream cos =
spy(CachedOutputStream.class`). Then after this, there was a line
`verify(cos).setThreshold(102400L)`. Therefore, after the cos being
initialized, we need to make sure the setThreshold has been called once.
However, it doesn't execute as expected, and the root cause is that
1. the threshold is not provided when calling
`testSetStreamedAttachmentProperties()` method -> so the setThreshold() won't
be called in line 198 in AttachmentUtil.java and
2. the `thresholdSysPropSet` (the boolean that indicated whether the default
threshold has been set or not) has been set to true when we run the
`CachedOutputStreamTest.java`. Inside the `CachedOutputStreamTest.java`, the
unit test `testUseSysPropsWithAttachmentDeserializer()` called the
`AttachmentUtil.setStreamedAttachmentProperties(message, cache`), so the
`thresholdSysPropSet`has been set to true then. -> so the
etThreshold(AttachmentDeserializer.THRESHOLD) won't be called in line 215 in
AttachmentUtil.java.
Since none of them being called, the verify(cos).setThreshold(102400L) will
complained that setThreshold() was not invoked.
Therefore, if we run `CachedOutputStreamTest.java` before running the
`AttachmentUtilTest.java`, the `verify(cos).setThreshold(102400L)` statement
will lead to the error message
```
Wanted but not invoked:
cachedOutputStream.setThreshold(102400L);
-> at
org.apache.cxf.attachment.AttachmentUtilTest.bigIntAsAttachmentMaxSize(AttachmentUtilTest.java:279)
```
**Fix log**
After debugging the code, it is clear that the `thresholdSysPropSet` should
be `False` every time the CachedOutputStream object was initialized. Therefore,
I add the method `resetDefaultThreshold()` in the `CachedOutputStream.java`. In
the test class `AttachmentUtilTest`, I called this reset method after
initializing the new CachedOutputStream(). After this fix, the failure has been
solved.
**How this has been tested**
Java: openjdk version "17.0.8.1"
Maven: Apache Maven 3.9.5
**How to reproduce the failure**
`mvn install -pl core -am -DskipTests`
(must setup iDFlakies on a Maven project -
https://github.com/UT-SE-Research/iDFlakies)
`mvn -pl core idflakies:detect -Ddetector.detector_type=random-class-method
-Ddt.randomize.rounds=10 -Ddt.detector.original_order.all_must_pass=false`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]