Skip to content

fixing flaky tests in UserRepositoryStoredProcedureIntegrationTests.java #2364

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

Closed
wants to merge 1 commit into from

Conversation

FanYuliang
Copy link
Contributor

Hi,

These two flaky tests (entityAnnotatedCustomNamedProcedurePlus1IO2 and entityAnnotatedCustomNamedProcedurePlus1IOoptional) are detected by using NonDex using the following command: mvn -pl . edu.illinois:nondex-maven-plugin:1.1.2:nondex -Dtest=org.springframework.data.jpa.repository.UserRepositoryStoredProcedureIntegrationTests

These two tests are flaky because Map<String, Integer> result is not in order, and therefore the containsExactly may be flaky. I updated it into containsOnly to make sure the assertion is order independent.

  • 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).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 24, 2021
@quaff
Copy link
Contributor

quaff commented Dec 1, 2021

Map implementation could be LinkedHashMap which is ordered, do you encounter failed tests or only detected by NonDex?

@FanYuliang
Copy link
Contributor Author

The tests works fine on my JVM, but NonDex will shuffle the order of elements in Map to simulate the indeterministic feature so that developers can find the potential flaky tests. Since the implementation of Map could also be Hashmap, I think it will be safer to use containsOnly to prevent the potential flakiness due to different implementation of Map.

@quaff
Copy link
Contributor

quaff commented Dec 1, 2021

The tests works fine on my JVM, but NonDex will shuffle the order of elements in Map to simulate the indeterministic feature so that developers can find the potential flaky tests. Since the implementation of Map could also be Hashmap, I think it will be safer to use containsOnly to prevent the potential flakiness due to different implementation of Map.

What if ordering is mandatory here?

@FanYuliang
Copy link
Contributor Author

If order is maintained (Map uses LinkedHashMap for example), then there won't no flakiness in the test. But I didn't find any order consistency in the NamedStoredProcedureQuery : as described in the docs,

If there are multiple out parameters specified in a @NamedStoredProcedureQuery annotation those can be returned as a Map with the key being the parameter name given in the @NamedStoredProcedureQuery annotation.

I didn't find in the doc saying that the Map uses implementation of LinkedHashMap, so I assume the output Map should be indeterministic and might be flaky.

schauder pushed a commit that referenced this pull request Dec 7, 2021
@schauder
Copy link
Contributor

schauder commented Dec 7, 2021

Thanks, that's merged.

@schauder schauder closed this Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants