spring-data-keyvalue
spring-data-keyvalue copied to clipboard
Fix 2 Flaky Tests
- [☑️] You have read the Spring Data contribution guidelines.
- [☑️] You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
- [☑️] You submit test cases (unit or integration tests) that back your changes.
- [☑️] You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).
This PR fixes 2 potential flaky tests in MapKeyValueAdapterUnitTests.java
file.
In the test scanShouldIterateOverAvailableEntries()
, we rely on the fact that the map has a specific order. However, as the key space map for COLLECTION_1 is initialized as a ConcurrentHashMap
, it is not guaranteed that the order will remain constant over time according to the Java documentation.
Because the elements of a ConcurrentHashMap are not ordered in any particular way, and may be processed in different orders in different parallel executions, the correctness of supplied functions should not depend on any ordering, or on any other objects or values that may transiently change while computation is in progress;
Such indeterministic characteristic of ConcurrentHashMap will cause this test to fail in some platforms or specific machines that adopt a different iteration order.
To fix it, I will first iterate through all the entries in the map, and based on the key of the first entry, we then compare two entries accordingly.
The same fix also applies to scanDoesNotMixResultsFromMultipleKeyspaces()
.