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 flaky test for pick_should_pick_key_pairs_corresponding_to_keys #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MyEnthusiastic
Copy link

@MyEnthusiastic MyEnthusiastic commented Sep 28, 2023

This PR is to fix a flaky test snippets.SnippetsTests#pick_should_pick_key_pairs_corresponding_to_keys

setup

Java version: 1.8.0_382
Maven version: Apache Maven 3.6.3

Test failure Reproduction

The test snippets.SnippetsTests#pick_should_pick_key_pairs_corresponding_to_keys can fail as the underlying code uses a HashMap and containsExactly assumes the order of the elements in the HashMap This issue was verified using the NonDex plugin.

Steps:

Use the nondex .sh script from "Helper scripts in cmds" section

./nondex.sh . snippets.SnippetsTests#pick_should_pick_key_pairs_corresponding_to_keys

NonDex test failure:

[ERROR] Failures: 
[ERROR]   SnippetsTests.pick_should_pick_key_pairs_corresponding_to_keys:331 
Actual and expected have the same elements but not in the same order, at index 0 actual element was:
  <MapEntry[key="c", value=3]>
whereas expected element was:
  <a=1>

[INFO] 
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO] 

Root cause and fix

containsExactly assumes the order of the elements in the HashMap, so using containsOnly can be order agnostic. But contains only broaden the concept about the exactly, so we check the size first then compare the content

@MyEnthusiastic MyEnthusiastic changed the title use contains only for bug fix None Sep 28, 2023
@MyEnthusiastic MyEnthusiastic changed the title None Fix flaky test Nov 4, 2023
@MyEnthusiastic MyEnthusiastic changed the title Fix flaky test Fix flaky test for pick_should_pick_key_pairs_corresponding_to_keys Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant