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

Fix flaky test testToJSONString #2723

Merged
merged 1 commit into from
Oct 31, 2023

Conversation

219sansim
Copy link
Contributor

Problem

The testToJSONString is detected flaky because the JsonHelper.toJSONString() gives a non-deterministic output as JSONObject values are unordered.

Solution

After modifying testToJSONString to expect 2 different string values, the test passes.

Reason:
The JSON object is unordered and generally uses Maps as their internal data structure. And, according to HashMap documentation,
"This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time."
This causes the JsonHelper.toJSONString() to give a non-deterministic output.

Reproduction of the error

The test fails on 5/10 runs of the NonDex tool

Command to reproduce the failure:
mvn -pl pac4j-oauth edu.illinois:nondex-maven-plugin:2.1.7-SNAPSHOT:nondex -Dtest=org.pac4j.oauth.profile.JsonHelperTests#testToJSONString -DnondexRuns=10

Error Message:

[ERROR] org.pac4j.oauth.profile.JsonHelperTests.testToJSONString -- Time elapsed: 0.396 s <<< FAILURE!
org.junit.ComparisonFailure: expected:<"{\"[id\":\"id\",\"name\":\"name]\"}"> but was:<"{\"[name\":\"name\",\"id\":\"id]\"}">

@leleuj leleuj merged commit b27dda4 into pac4j:master Oct 31, 2023
4 checks passed
@leleuj
Copy link
Member

leleuj commented Oct 31, 2023

Thanks for your contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants