Fixed test failures caused by non-deterministic order of style map #1817
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.
Created this PR to fix 19 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 style map, which is used to create a part of the
json
variable structure in the tests (here). The tests were asserting the exact order of keys in the generated JSON, including properties like paddingBottom, whiteSpace, overflow, color, and paddingTop. Since the implementation was using a HashMap to create the style 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 style map's keys in the json:
To address the non-deterministic order of keys, I replaced the usage of HashMap with LinkedHashMap when creating the style 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 adding elements to style map in the expected order to fix all the listed tests.
You can run the following commands to run the 19 tests using NonDex tool respectively:
Test Environment:
Kindly let me know if this fix is acceptable.
Thank you