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 tests #1204

Merged
merged 3 commits into from
May 22, 2024
Merged

Fix flaky tests #1204

merged 3 commits into from
May 22, 2024

Conversation

asolntsev
Copy link
Collaborator

No description provided.

Sometimes if failed when "now + 1 minute" was in tomorrow.

For example:
java.lang.IllegalArgumentException: Invalid time range: the upper bound time (00:00:47.593917390) is before the lower bound (23:59:47.593917390)
Sometimes if failed when two paralle threads modify field `shuffledLocales`.

For example:
```
net.datafaker.integration.FakerRepeatabilityIntegrationTest.shouldCreateUniqueValues -- Time elapsed: 0.890 s <<< ERROR!
java.lang.IndexOutOfBoundsException: Index 69 out of bounds for length 69
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
	at java.base/java.util.Objects.checkIndex(Objects.java:361)
	at java.base/java.util.ArrayList.remove(ArrayList.java:504)
	at net.datafaker.providers.base.Locality.localeStringWithoutReplacement(Locality.java:174)
	at net.datafaker.providers.base.Locality.localeStringWithoutReplacement(Locality.java:156)
```
it's not needed to remove the element from shuffledLocales and resize the underlying array.
It's enough just to keep an index of current element in this list.
Copy link

what-the-diff bot commented May 22, 2024

PR Summary

  • Enhanced Locality Feature Adjustment
    This update involves a modification in the Locality feature. A new field, shuffledLocaleIndex has been added and changes were made in the localeStringWithoutReplacement method. The benefit of this change is that it allows the localeStringWithoutReplacement method to return the next locale in an orderly sequence, thus offering a predictable and simple iteration over the locales.

  • Exception Handling for Time Boundaries
    The Time feature's between method has been updated to throw an informative exception message when bound measurements are violated, specifically if the upper bound time is set before the lower bound. This improves error reporting and ensures the client has the correct details to address these mismatched time boundaries.

  • Unit Testing Adjustments
    Updates have been made in the TimeTest feature. Changes specifically revolve around the improvement of the testBetweenThenLargerThanNow method to accommodate the new formatted exception message, and amendments to the testBetweenWithMask method. The latter now verifies that the result of the between method aligns with a pre-specified pattern and asserts that the parsed time falls within an acceptable time frame.

  • Introduction of New Constants
    The addition of RE_TIME_BETWEEN, NANOSECONDS_IN_DAY, and NANOSECONDS_IN_MINUTE constants serve to enhance precision within time computations and ensure greater accuracy and consistency across the system.

Copy link
Collaborator

@snuyanzin snuyanzin left a comment

Choose a reason for hiding this comment

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

Thanks for improving it
LGTM

@snuyanzin snuyanzin merged commit bf92b8e into datafaker-net:main May 22, 2024
10 checks passed
@asolntsev asolntsev deleted the fix/flaky-tests branch May 23, 2024 05:37
@asolntsev asolntsev self-assigned this May 26, 2024
@asolntsev asolntsev added the enhancement New feature or request label May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants