EJBCLIENT-418 fixed test flakniess due to indeterminate HashMap ordering #534
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://issues.redhat.com/browse/EJBCLIENT-418
Description
The test
testInvocationOnMixedModeCluster()
inMixedModeServiceURLTestCase.java
can fail nondeterministically. The issue is found using Nondex when running commandsmvn edu.illinois:nondex-maven-plugin:1.1.2:nondex -Dtest=MixedModeServiceURLTestCase
underjavax
directory after building all dependencies. The problem is in the functionvalidateResults()
that deals withServiceURL
. InNodeInformation.java
, the code callsServiceURL.Builder.create()
(e.g. line 216), which uses the default iterator of aHashMap.entrySet()
. An EntrySet of a normal HashMap does not guarantee any order. Therefore,serviceURL
may have internal order permutation. WhentoString()
is called, a sample output String can be"service:ejb.jboss:remote://localhost:7099;node=node2;cluster=mixed-ejb;ejb-module=my-foo-app/my-bar-module"
in one run, and then"service:ejb.jboss:remote://localhost:7099;cluster=mixed-ejb;node=node2;ejb-module=my-foo-app/my-bar-module"
in another run. These possibilities can make the unit test fail occasionally.Reasons for Fixing
The test may fail been run in a different enviornment or when Java upgrades in the future.
Fixes
Split the String formatted
ServiceURL
by semicolon. Then convert the output String Array into a HashSet to allow order permutation. Then do a direct comparison between the nested HashSets.