Changed HashMap to LinkedHashMap for deterministic order (description,value,key) #1820
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.
Note: This PR fixes all the tests failures (19) mentioned in PR: https://github.com/mock-server/mockserver/pull/1817/files in addition to the test failures(8) mentioned in this PR i.e total tests fixed = 27
Created this PR to fix 8 flaky tests listed as follows:
How were these test identified as flaky?
These tests were identified as flaky by using an open-source research tool named NonDex which is responsible for finding and diagnosing non-deterministic runtime exceptions in Java programs.
What was the error?
The error was caused by non-deterministic ordering of keys in the entry map here and here. The tests were asserting the exact order of keys in the generated JSON in the following order: description, value, key. Since the implementation was using a HashMap to create the entry map, the order of keys was not guaranteed, leading to different orders during test execution.
Common Error among all the tests mentioned below - jumbled ordering of entry map's keys (i.e description, value, key) in the json:
To address the non-deterministic order of keys, I replaced the usage of HashMap with LinkedHashMap when creating the entry map. Unlike HashMap, LinkedHashMap preserves the order of keys based on their insertion order. By explicitly ordering the keys in the style map according to the expected order, we can ensure consistent ordering during each test run. This PR proposes changing HashMap to LinkedHashMap here and here and adding elements to style map in the expected order to fix all the listed tests.
You can run the following commands to run the 8 tests using NonDex tool respectively:
Test Environment:
Kindly let me know if this fix is acceptable.
Thank you