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

[core] Fix flaky SummaryHTMLRenderer #4750

Merged
merged 1 commit into from Nov 23, 2023

Conversation

219sansim
Copy link
Contributor

Describe the PR

The test SummaryHTMLRendererTest.testRendererMultiple assumes a particular order for the keys stored in summary map.
The following lines of code in renderSummary function may return any random field ordering. This might cause inconsistent output rendering and results in the unit test being flaky.

Map<String, MutableInt> summary = getSummary(report);
for (Entry<String, MutableInt> entry : summary.entrySet()) {
String ruleName = entry.getKey();
writer.write("<tr><td>");
writer.write(ruleName);
writer.write("</td><td align=center>");
writer.write(String.valueOf(entry.getValue().intValue()));
writer.println("</td></tr>");
}

Changing the HashMap to LinkedHashMap, makes the output consistent and fixes the flaky test. There might be other possible fixes like, changing the test code such that, the tests expects and passes for both the orderings.

Steps to reproduce the flaky test

Setup the NonDex tool in your repo and run

mvn -pl pmd-core -Dtest=net.sourceforge.pmd.renderers.SummaryHTMLRendererTest#testRendererMultiple

Error Message

net.sourceforge.pmd.renderers.SummaryHTMLRendererTest.testRendererMultiple  Time elapsed: 0.002 s  <<< FAILURE!
org.opentest4j.AssertionFailedError: 
expected: <<html><head><title>PMD</title></head><body>
<center><h2>Summary</h2></center>
<table align="center" cellspacing="0" cellpadding="3">
<tr><th>Rule name</th><th>Number of violations</th></tr>
<tr><td>Boo</td><td align=center>1</td></tr>
<tr><td>Foo</td><td align=center>1</td></tr>
</table>
<center><h2>Detail</h2></center><table align="center" cellspacing="0" cellpadding="3"><tr>
<center><h3>PMD report</h3></center><center><h3>Problems found</h3></center><table align="center" cellspacing="0" cellpadding="3"><tr>
<th>#</th><th>File</th><th>Line</th><th>Problem</th></tr>
<tr bgcolor="lightgrey"> 
<td align="center">1</td>
<td width="*%"><a href="link_prefixnotAvailable.html#line_prefix1">notAvailable</a></td>
<td align="center" width="5%">1</td>
<td width="*">blah</td>
</tr>
<tr> 
<td align="center">2</td>
<td width="*%"><a href="link_prefixnotAvailable.html#line_prefix1">notAvailable</a></td>
<td align="center" width="5%">1</td>
<td width="*">blah</td>
</tr>
</table></tr></table></body></html>
> but was: <<html><head><title>PMD</title></head><body>
<center><h2>Summary</h2></center>
<table align="center" cellspacing="0" cellpadding="3">
<tr><th>Rule name</th><th>Number of violations</th></tr>
<tr><td>Foo</td><td align=center>1</td></tr>
<tr><td>Boo</td><td align=center>1</td></tr>
</table>
<center><h2>Detail</h2></center><table align="center" cellspacing="0" cellpadding="3"><tr>
<center><h3>PMD report</h3></center><center><h3>Problems found</h3></center><table align="center" cellspacing="0" cellpadding="3"><tr>
<th>#</th><th>File</th><th>Line</th><th>Problem</th></tr>
<tr bgcolor="lightgrey"> 
<td align="center">1</td>
<td width="*%"><a href="link_prefixnotAvailable.html#line_prefix1">notAvailable</a></td>
<td align="center" width="5%">1</td>
<td width="*">blah</td>
</tr>
<tr> 
<td align="center">2</td>
<td width="*%"><a href="link_prefixnotAvailable.html#line_prefix1">notAvailable</a></td>
<td align="center" width="5%">1</td>
<td width="*">blah</td>
</tr>
</table></tr></table></body></html>
>

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

@adangel adangel changed the title Fix flaky SummaryHTMLRenderer [core] Fix flaky SummaryHTMLRenderer Nov 23, 2023
@adangel adangel added the a:bug PMD crashes or fails to analyse a file. label Nov 23, 2023
@adangel adangel added this to the 7.0.0 milestone Nov 23, 2023
@pmd-test
Copy link

1 Warning
⚠️ Running pmdtester failed, this message is mainly used to remind the maintainers of PMD.

Generated by 🚫 Danger

Copy link
Member

@adangel adangel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

adangel added a commit that referenced this pull request Nov 23, 2023
adangel added a commit that referenced this pull request Nov 23, 2023
@adangel adangel merged commit 49bf440 into pmd:master Nov 23, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug PMD crashes or fails to analyse a file.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants