Fix under-determined test: testWithParam #2737
Merged
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.
Checklist
Description of change
This PR aims to fix an under-determined test: org.apereo.portal.url.CasLoginRefUrlEncoderTest.testWithParam
I found and confirmed the failure of the test using an open-source research tool NonDex, which shuffles implementations of nondeterminism operations.
Problem
The test case org.apereo.portal.url.CasLoginRefUrlEncoderTest.testWithParam fails due to the below assertion:
uPortal/uPortal-security/uPortal-security-mvc/src/test/java/org/apereo/portal/url/CasLoginRefUrlEncoderTest.java
Lines 66 to 68 in 23e387d
This is because, findMatchingServerName returns the first element from
allServerNames
collection.uPortal/uPortal-utils/uPortal-utils-url/src/main/java/org/apereo/portal/url/UrlMultiServerNameCustomizer.java
Line 63 in 5d1d743
Since
allServerNames
is aHashSet
, the order of the items"myhost:8080", "theirhost:8443"
in theHashSet
is not preserved. Hence the server name returned byfindMatchingServerName
may vary which may cause the test testWithParam to fail in a hypothetical future.Solution
This PR fixes the test by using a
LinkedHashSet
to storeallServerNames
sinceLinkedHashSet
preserves the order of the elements.Steps to reproduce
The following command can be used to reproduce the assertion errors and verify the fix.
Integrate NonDex:
Add the following snippet to the top of the build.gradle in $PROJ_DIR:
Append to build.gradle in $PROJ_DIR:
Execute Test with Gradle:
Run NonDex:
Test Environment:
Please let me know if you have any concerns or questions.