Skip to content

Use Collection.Sort and compare the contents of the list to fix the flaky test#1

Open
prathyushreddylpr wants to merge 2 commits into
mainfrom
cxf_dev
Open

Use Collection.Sort and compare the contents of the list to fix the flaky test#1
prathyushreddylpr wants to merge 2 commits into
mainfrom
cxf_dev

Conversation

@prathyushreddylpr

Copy link
Copy Markdown
Owner

Description

Fixed the flaky test testGetFiles inside FileUtilsTest.java class.

public void testGetFiles() throws URISyntaxException {

Root Cause

The test testGetFiles has been reported as flaky when run with the NonDex tool. The test failed because it is trying to compare contents in two lists, but since the order is not maintained in lists the assert is failing. The List in Java is implemented in such a way that it does not store the order in which the values are inserted. As a result, when both the lists are compared, it caused the failure.

Fix

This test is fixed by first sorting the two lists and then comparing both lists.

How this has been tested?

Java: openjdk version "11.0.20.1"
Maven: Apache Maven 3.6.3

  1. Module build - Successful
    Command used -
mvn install -pl core -am -DskipTests
  1. Regular test - Successful
    Command used -
mvn -pl core test -Dtest=org.apache.cxf.helpers.FileUtilsTest#testGetFiles
  1. NonDex test - Failed
    Command used -
mvn -pl core edu.illinois:nondex-maven-plugin:2.1.7-SNAPSHOT:nondex -Dtest=org.apache.cxf.helpers.FileUtilsTest#testGetFiles

NonDex test passed after the fix.

@Nemesis123925

Copy link
Copy Markdown
  1. Looks like a simple fix to me. But I wander what's the root cause of this flakyness. I think if the original tests compairs Lists, then the order of element in the list is not a neglibiable element, otherwire it will use other datastructurs like Set.

  2. Is there possibility that some original failed cases will pass the new test because you sort the List?

@zzjas

zzjas commented Oct 26, 2023

Copy link
Copy Markdown

You can proceed to open a real PR. Once you open a real PR, please mark this tentative PR as Opened in your tentative_pr.csv file and also raise a PR to IDoFT marking this as Opened. Thanks!

@Einsteinnnnn

Copy link
Copy Markdown

The fix is simple enough, I think it's a good fix.

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.

4 participants