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

[WFCORE-6214] Fixed Flaky Tests in HelpSupportTestCase.testStandalone and BootScriptInvokerTestCase #5366

Merged
merged 1 commit into from Feb 15, 2023

Conversation

RishabhPrabhu5
Copy link
Contributor

@RishabhPrabhu5 RishabhPrabhu5 commented Jan 30, 2023

What is the purpose of this PR

  • This PR fixes the error resulting from two flaky tests: org.jboss.as.cli.impl.aesh.HelpSupportTestCase and org.jboss.as.cli.impl.BootScriptInvokerTestCase
  • The mentioned tests may fail or pass without changes made to the source code when it is run in different JVMs due to HashSet's non-deterministic iteration order.

Why the tests fail

  • Test one fails because HelpSupportTestCase calls SynopsisGenerator, which uses a HashSet as its data structure for the conflicts object. As per Java 11 documentation, the ordering of HashSet is not constant. So, the test may fail as the given order can be different from the expected order.
  • Test two fails because BootScriptInvokerTestCase#test uses a HashSet as its data structure for the echos object. As per Java 11 documentation, the ordering of HashSet is not constant. So, the test may fail as the given order can be different from the expected order.

Reproduce the test failure

  • Run the tests with NonDex maven plugin. The commands to recreate the flaky test failures are:

  • mvn -pl cli edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=org.jboss.as.cli.impl.aesh.HelpSupportTestCase#testStandalone

  • mvn -pl cli edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=org.jboss.as.cli.impl.BootScriptInvoker#test

  • Fixing the flaky test now may prevent flaky test failures in future Java versions.

Expected results

  • Both tests should run successfully when run with NonDex.

Actual Result

  • We get the following failure for test org.jboss.as.cli.impl.aesh.HelpSupportTestCase#testStandalone :
    [ERROR] testStandalone(org.jboss.as.cli.impl.aesh.HelpSupportTestCase) Time elapsed: 0.254 s <<< FAILURE!
    org.junit.ComparisonFailure: org.jboss.as.cli.impl.aesh.Commands$Standalone$Command10. EXPECTED [command1 [<argument>] ( [--all-server-groups] | [--replace] | [--server-groups] )]. FOUND [command1 [<argument>] ( [--all-server-groups] | [--server-groups] | [--replace] )] expected: <...server-groups] | [--[replace] | [--server-groups]] )> but was: <...server-groups] | [--[server-groups] | [--replace]] )>

  • We get the following failure for test org.jboss.as.cli.impl.BootScriptInvokerTestCase#test:
    <<< FAILURE! - in org.jboss.as.cli.impl.BootScriptInvokerTestCase [ERROR] test(org.jboss.as.cli.impl.BootScriptInvokerTestCase) Time elapsed: 0.066 s <<< FAILURE!
    java.lang.AssertionError

Fix

  • For test one: Changed the object type of conflicts2 from HashSet to TreeSet in method org.jboss.as.cli.impl.aesh.SynopsisGenerator#addSynopsisOption(SynopsisOption).
  • For test two: Changed the object type of echos from HashSet to LinkedHashSet in org.jboss.as.cli.impl.BootScriptInvokerTestCase#test

Jira Issue:

https://issues.redhat.com/browse/WFCORE-6214

This PR is similar to some merged PRs in other Wildfly projects:

wildfly/wildfly#13728
wildfly/wildfly#11833
wildfly/jboss-ejb-client#534

@wildfly-ci
Copy link

Hello, RishabhPrabhu5. I'm waiting for one of the admins to verify this patch with /ok-to-test in a comment.

@yersan
Copy link
Collaborator

yersan commented Jan 30, 2023

Hi @RishabhPrabhu5 , thank you for contributing to WildFly!

Could you add the Jira number to the commit message? Like what you did with the title, having the Jira number in the commit message is a requirement for us. It helps us to track the history with the Jira issue.

Set<SynopsisOption> conflicts = new HashSet<>(currentOption.conflictWith);
Set<SynopsisOption> conflicts2 = new HashSet<>(currentOption.conflictWith);
Set<SynopsisOption> conflicts = new LinkedHashSet<>(currentOption.conflictWith);
Set<SynopsisOption> conflicts2 = new LinkedHashSet<>(currentOption.conflictWith);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that the correct fix would be to use

Set<SynopsisOption> conflicts2 = new TreeSet<>(Comparator.comparing(SynopsisOption::getName));
conflicts2.addAll(currentOption.conflictWith);

In order to iterate the conflicts using the natural ordering of Options (name).

@@ -180,8 +181,8 @@ private String addSynopsisOption(SynopsisOption currentOption) {
}
synopsisBuilder.append(" |");
// Keep the set of all conflicts, they will be removed from all conflicts, being handled at this level.
Set<SynopsisOption> conflicts = new HashSet<>(currentOption.conflictWith);
Set<SynopsisOption> conflicts2 = new HashSet<>(currentOption.conflictWith);
Set<SynopsisOption> conflicts = new LinkedHashSet<>(currentOption.conflictWith);
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is not needed.

@jfdenise
Copy link
Contributor

@RishabhPrabhu5 thank-you for your fix. I added a comment.

Running your plugin I found another one in : https://github.com/wildfly/wildfly-core/blob/main/cli/src/test/java/org/jboss/as/cli/impl/BootScriptInvokerTestCase.java#L217
Should be a LinkedHashSet. Would you be ok to update the JIRA description and also fix this one? The JIRA would be the findings running the plugin against CLI unit tests.

Thank-you!

@RishabhPrabhu5 RishabhPrabhu5 changed the title [WFCORE-6214] Fixed Flaky Test HelpSupportTestCase.testStandalone [WFCORE-6214] Fixed Flaky Tests in HelpSupportTestCase.testStandalone and BootScriptInvokerTestCase Feb 11, 2023
@RishabhPrabhu5
Copy link
Contributor Author

Thank you for the feedback, I have made the changes requested and have updated the JIRA description. Please let me know if there is anything more I can do.
Thank you!

@yersan
Copy link
Collaborator

yersan commented Feb 13, 2023

/ok-to-test

@yersan yersan requested a review from jfdenise February 14, 2023 09:58
@yersan
Copy link
Collaborator

yersan commented Feb 14, 2023

Windows - Bootable JAR - JDK 11 is unrelated to this PR.

@yersan yersan added the ready-for-merge This PR is ready to be merged and fulfills all requirements label Feb 15, 2023
@yersan yersan merged commit 052dff9 into wildfly:main Feb 15, 2023
@yersan
Copy link
Collaborator

yersan commented Feb 15, 2023

@RishabhPrabhu5 , merged!, thanks for contributing to WildFly, and especially for the great PR description, that helps in doing the review.

@RishabhPrabhu5
Copy link
Contributor Author

RishabhPrabhu5 commented Feb 15, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deps-ok Dependencies have been checked, and there are no significant changes ready-for-merge This PR is ready to be merged and fulfills all requirements
Projects
None yet
4 participants