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 LatticeRelationTest #4752

Merged
merged 2 commits into from
Mar 15, 2024

Conversation

219sansim
Copy link
Contributor

@219sansim 219sansim commented Nov 24, 2023

Describe the PR

Problem
The LatticeRelationTest.testToString is detected as flaky. The following lines of code iterate over vertices which is of Type Set.



Java does not iterate over elements of a set in a particular order. This causes the output toString function to be non-deterministic and results in the LatticeRelationTest.testToString to be flaky.
Solution
I have modified the code such that we iterate over a sorted list of Vertex objects. This results in the toString output being deterministic. I had to modify the expected string in the test assertion to account for the sorting.
Another possible fix would be to modify the test itself and change the assert to expect multiple different string ordering values.

Steps to reproduce the flaky test

Setup the NonDex tool and run

mvn -pl pmd-core edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=net.sourceforge.pmd.lang.rule.internal.LatticeRelationTest#testToString

Error Message

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.077 s <<< FAILURE! - in net.sourceforge.pmd.lang.rule.internal.LatticeRelationTest
[ERROR] net.sourceforge.pmd.lang.rule.internal.LatticeRelationTest.testToString  Time elapsed: 0.047 s  <<< FAILURE!
org.opentest4j.AssertionFailedError: 
expected: <strict digraph {
n0 [ shape=box, color=green, label="[]" ];
n1 [ shape=box, color=green, label="[1]" ];
n2 [ shape=box, color=green, label="[2]" ];
n3 [ shape=box, color=black, label="[1, 2]" ];
n1 -> n0;
n2 -> n0;
n3 -> n0;
n3 -> n1;
n3 -> n2;
}> but was: <strict digraph {
n0 [ shape=box, color=green, label="[2]" ];
n1 [ shape=box, color=green, label="[]" ];
n2 [ shape=box, color=black, label="[1, 2]" ];
n3 [ shape=box, color=green, label="[1]" ];
n0 -> n1;
n2 -> n0;
n2 -> n1;
n2 -> n3;
n3 -> n1;
}>

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)

@pmd-test
Copy link

pmd-test commented Nov 24, 2023

1 Message
📖 Compared to master:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Download full report as build artifact
Compared to master:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Download full report as build artifact

Generated by 🚫 Danger

Copy link
Member

@oowekyala oowekyala left a comment

Choose a reason for hiding this comment

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

Thank you for identifying and fixing this!

@adangel adangel added this to the 7.0.0 milestone Mar 14, 2024
Co-authored-by: Clément Fournier <clem.fournier@proton.me>
@adangel adangel changed the title Fix flaky LatticeRelationTest [core] Fix flaky LatticeRelationTest Mar 15, 2024
adangel added a commit that referenced this pull request Mar 15, 2024
adangel added a commit that referenced this pull request Mar 15, 2024
@adangel adangel merged commit 3237f13 into pmd:master Mar 15, 2024
3 checks passed
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