Skip to content

Fix flaky test PolarPlotTest.testGetLegendItems2#387

Open
Sujishark wants to merge 1 commit intojfree:masterfrom
Sujishark:fix-flaky
Open

Fix flaky test PolarPlotTest.testGetLegendItems2#387
Sujishark wants to merge 1 commit intojfree:masterfrom
Sujishark:fix-flaky

Conversation

@Sujishark
Copy link
Copy Markdown

This PR aims to fix a test:

org.jfree.chart.plot.PolarPlotTest.testGetLegendItems2

This was found by using the NonDex tool.

Encountered the following error after running NonDex:

in org.jfree.chart.plot.PolarPlotTest
[ERROR] org.jfree.chart.plot.PolarPlotTest.testGetLegendItems2  Time elapsed: 0.053 s  <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: <A> but was: <C>
at org.jfree.chart@2.0.0-SNAPSHOT/org.jfree.chart.plot.PolarPlotTest.testGetLegendItems2(PolarPlotTest.java:108)

REASON AND FIX

The tests fail when the function values of 'items' are compared using assert statements intestGetLegendItems2. This is because the 'renderers' in Plot are set using HashMap which maintains a non-deterministic order.

this.renderers = new HashMap<>();

According to HashMap documentation,
"This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time."

This can be solved by changing from HashMap to LinkedHashMap to maintain a permanent deterministic order.

Reproduce:

The following command can be used to replicate the failures and validate the fix:

mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=org.jfree.chart.plot.PolarPlotTest#testGetLegendItems2

Environment:

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

No user-facing change.
No dependency upgrade.

Author:    rajan11 <rajan11@illinois.edu>
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.

1 participant