add a DateTimeProvider for making retry after testable#391
add a DateTimeProvider for making retry after testable#391marandaneto merged 3 commits intogetsentry:masterfrom marandaneto:ref/datetime-provider
Conversation
philipphofmann
left a comment
There was a problem hiding this comment.
Nice that we have a CurrentDateProvider now. I added a few suggestions to hopefully improve this a little bit.
sentry-core/src/main/java/io/sentry/core/transport/ICurrentDateProvider.java
Outdated
Show resolved
Hide resolved
| var readTimeout = 500 | ||
| var bypassSecurity = false | ||
| val connection = mock<HttpURLConnection>() | ||
| val currentDateProvider = mock<ICurrentDateProvider>() |
There was a problem hiding this comment.
Instead of mocking this all the time, we could implement a TestCurrentDateProvider that always returns the same time like new Date(0) and use it here. Makes the code cleaner IMO.
There was a problem hiding this comment.
we'd need to have more than 1 fake though, as tests would need to return also values different than Date(0) eg if isRetryAfter returns false when the time has passed.
I think it's not a good idea and also not sure how to test this use case if the return is always the same?
what's your LOGAF here?
sentry-core/src/test/java/io/sentry/core/transport/HttpTransportTest.kt
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #391 +/- ##
=========================================
Coverage ? 59.75%
Complexity ? 788
=========================================
Files ? 89
Lines ? 3620
Branches ? 350
=========================================
Hits ? 2163
Misses ? 1305
Partials ? 152
Continue to review full report at Codecov.
|
📢 Type of change
📜 Description
add a DateTimeProvider for making retry after testable
💡 Motivation and Context
we were using Thread.sleep(x) and this was slowing down the tests and could also become flakey, with this we can assert things properly.
thanks @philipphofmann for the code review #381 good catch.
💚 How did you test it?
unit tests.
📝 Checklist
🔮 Next steps