Skip to content

Fix flaky test TimeAndDateTest.testPastDate#1216

Merged
asolntsev merged 2 commits intodatafaker-net:mainfrom
asolntsev:refactoring/add-details-to-thrown-errors
May 25, 2024
Merged

Fix flaky test TimeAndDateTest.testPastDate#1216
asolntsev merged 2 commits intodatafaker-net:mainfrom
asolntsev:refactoring/add-details-to-thrown-errors

Conversation

@asolntsev
Copy link
Collaborator

@asolntsev asolntsev commented May 25, 2024

Also, add details to thrown errors.

@codecov-commenter
Copy link

codecov-commenter commented May 25, 2024

Codecov Report

Attention: Patch coverage is 42.25352% with 41 lines in your changes are missing coverage. Please review.

Project coverage is 92.05%. Comparing base (b37c566) to head (1029a8e).
Report is 111 commits behind head on main.

Files Patch % Lines
.../java/net/datafaker/service/FakeValuesService.java 20.00% 8 Missing ⚠️
...tafaker/transformations/JavaObjectTransformer.java 11.11% 8 Missing ⚠️
.../datafaker/transformations/sql/SqlTransformer.java 22.22% 4 Missing and 3 partials ⚠️
...n/java/net/datafaker/providers/base/BaseFaker.java 50.00% 6 Missing ⚠️
...ain/java/net/datafaker/providers/base/Hashing.java 0.00% 2 Missing ⚠️
...in/java/net/datafaker/providers/base/Locality.java 0.00% 2 Missing ⚠️
.../net/datafaker/transformations/XmlTransformer.java 0.00% 1 Missing and 1 partial ⚠️
...net/datafaker/transformations/YamlTransformer.java 0.00% 1 Missing and 1 partial ⚠️
...c/main/java/net/datafaker/providers/base/Text.java 50.00% 1 Missing ⚠️
.../java/net/datafaker/service/FakeValuesContext.java 0.00% 1 Missing ⚠️
... and 2 more

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1216      +/-   ##
============================================
- Coverage     92.35%   92.05%   -0.30%     
- Complexity     2821     2963     +142     
============================================
  Files           292      304      +12     
  Lines          5609     5855     +246     
  Branches        599      624      +25     
============================================
+ Hits           5180     5390     +210     
- Misses          275      305      +30     
- Partials        154      160       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

} catch (Exception e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException("Failed to read path " + s, e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
throw new RuntimeException("Failed to read path " + s, e);
throw new RuntimeException("Failed to read path '" + s + "'", e);

sometimes when string is empty such output with quotes could save time during debug
another version with formatting is also ok

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, fixed.

.generate())
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Max length must be not less than min length and not negative");
.hasMessage("Max length (5) must be not less than min length (10) and not negative");
Copy link
Collaborator

Choose a reason for hiding this comment

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

wouldn't it be better to extract it into vars?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would say it makes this test more complex.
These values are pretty near and well-readable. After introducing variables, it will be harder to read this test.

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.

LGTM

I have a couple of minor comments

asolntsev added 2 commits May 25, 2024 21:32
it happened when
1. random TimeUnit was chosen NANOSECOND, but
2. random "atMost" (in milliseconds) was chosen lesser than 1000000 (it's less than 1 millisecond), so upperBoundMillis was equal to 1.

Sample stack trace:

```
java.lang.IllegalArgumentException: bound must be positive: -1

	at net.datafaker.service.RandomService.nextLong(RandomService.java:51)
	at net.datafaker.providers.base.TimeAndDate.past(TimeAndDate.java:182)
	at net.datafaker.providers.base.TimeAndDate.past(TimeAndDate.java:131)
	at net.datafaker.providers.base.TimeAndDate.past(TimeAndDate.java:119)
	at net.datafaker.providers.base.TimeAndDateTest.testPastDate(TimeAndDateTest.java:66)
```
@asolntsev asolntsev merged commit 2c3bb2b into datafaker-net:main May 25, 2024
@asolntsev asolntsev deleted the refactoring/add-details-to-thrown-errors branch May 25, 2024 18:51
@asolntsev asolntsev self-assigned this May 26, 2024
@asolntsev asolntsev added the bug Something isn't working label May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants