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

fixed 3 flaky tests in StringJoinTest.java #319

Closed
wants to merge 3 commits into from

Conversation

kevin952
Copy link

Flaky Test Fixes

Overview

This document outlines the issues identified in flaky tests and the corresponding fixes applied to address them. The changes were made in commit 36c63c3.

Tests 1, 2, 3: StringJoinTest.shouldJoinIterableOfStrings, StringJoinTest.shouldHandleNullDelimiter, StringJoinTest.shouldJoinIterableOfStringsWithDelimiter

Issue

Use of HashSet caused the assertions to fail as it does not maintain initial order of the elements.

Fix

Replaced newHashSet with a LinkedHashSet as it maintains initial order of the list and improves readability

Reproduction

To reproduce the error, use the following command for each test:

mvn -pl core edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=uk.gov.gchq.koryphe.impl.function.StringJoinTest -Dspotless.apply.skip -Dspotless.check.skip -DnondexRuns=10

Testing the Fixes

All fixes were tested by running the affected tests with the proposed changes to ensure reliability.

Conclusion

These changes aim to address flakiness in the identified tests and improve the overall stability of the test suite.

Additional Information

The fixes were identified and tested using the nondex tool.

Please do let me know if have any queries or these fixes look good to you!

@@ -48,7 +49,10 @@ public void shouldHandleNullInput() {
public void shouldHandleNullDelimiter() {
// Given
final StringJoin<String> function = new StringJoin<>(null);
final Set<String> input = Sets.newHashSet("a", "b", "c");
final Set<String> input = new LinkedHashSet<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an ArrayList could be used instead to keep this all on one line?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Used an ArrayList to clean up and use a single line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have made the input a Set with an ArrayList inside, which will work. However, for simplicity, I was thinking just make the input a List and don't use a Set at all.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. right. I assumed you wanted a set. but using a List makes sense as I believe it is deterministic and should solve the flakiness in the code!

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.

3 participants