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 2 Flaky Tests #407

Open
wants to merge 2 commits into
base: 2.7.x
Choose a base branch
from

Conversation

xiedaxia1hao
Copy link

  • [☑️] 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().

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 21, 2021
@christophstrobl christophstrobl self-assigned this May 8, 2023
@christophstrobl christophstrobl added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged labels May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task A general task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants