-
Notifications
You must be signed in to change notification settings - Fork 6
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
Refactor FlushManager
to Kotlin Coroutines
#86
Conversation
This class is relatively simple and difficult to test because of `java.utils.Timer`. That's why I decided to make migration to Kotlin right away, without unit tests coverage first.
The returned `Boolean` wasn't used anywhere.
Added a new test to validate the behavior of the FlushManager's queue when two timers are initiated sequentially. The test asserts that the queue flushes correctly as per the time of the first timer's start.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## coroutines #86 +/- ##
==============================================
+ Coverage 44.38% 46.15% +1.77%
==============================================
Files 8 10 +2
Lines 365 364 -1
Branches 56 57 +1
==============================================
+ Hits 162 168 +6
+ Misses 189 179 -10
- Partials 14 17 +3
☔ View full report in Codecov by Sentry. |
To give SDK time to prepare and trigger the HTTP request. 100ms is to small timeout for CI emulator. It's enough for local builds and Firebase Test Lab tests. There's no business logic mistake - just the CI emulator is extremly slow.
86d811f
to
1326644
Compare
|
||
Thread.sleep((flushInterval / 2).inWholeMilliseconds) | ||
|
||
val firstRequestPayload = server.takeRequest(2000, TimeUnit.MILLISECONDS)?.toMap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such a long waiting time is needed because of poor performance on GitHub Actions emulator. Also, the tests are executed differently, comparing to local execution (both device and same-settings emulator) and Firebase Test Lab. You can compare the logs, that just after [Parsely] Sending request with 2 events
log, GitHub Actions emulator sends test activity to Paused
(Lifecycle status change: com.parsely.parselyandroid.FunctionalTests$SampleActivity@316b36c in: PAUSED
), when it doesn't happen anywhere else...
All of this makes me think about pivoting to:
- using FIrebase Test Lab instead CI emulator
- moving from emulator-based functional test to Robolectric
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using FIrebase Test Lab instead CI emulator
Hmmm, maybe, not sure? 🤔
moving from emulator-based functional test to Robolectric
Hmmm, if I could vote, I would say to NOT making that move to Robolectric. 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 @wzieba !
I have reviewed and tested this PR as per the instructions, everything works as expected, great job, one more test suite live! 🌟 🧪 🌟
I have left few questions (❓) and a minor (🔍) comment for you to consider. I am going to approve this PR anyway, since none is blocking. I am NOT going to merge this PR yet to give you some time to apply any of my suggestions. However, feel free to ignore them and merge the PR yourself.
EXTRAS
Suggestion (💡): For this PR, and although it seems safe to merge by just depending on CI, I would still recommend having some actual manual testing instructions, to verify them and only then to proceed with merging this, even if that's just for documentation purposes. I am recommending that because FlushManager
has been completely re-written to Kotlin + Coroutines, plus, the test suite for it was added after the fact, not before. Just for us to be on the safe side, wdyt? 🤷
@@ -63,12 +64,14 @@ dependencies { | |||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.3' | |||
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1' | |||
implementation 'androidx.lifecycle:lifecycle-process:2.6.2' | |||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Praise (🎉): Woohoo! 🥇
parsely/src/main/java/com/parsely/parselyandroid/FlushManager.kt
Outdated
Show resolved
Hide resolved
parsely/src/main/java/com/parsely/parselyandroid/ParselyCoroutineScope.kt
Show resolved
Hide resolved
|
||
Thread.sleep((flushInterval / 2).inWholeMilliseconds) | ||
|
||
val firstRequestPayload = server.takeRequest(2000, TimeUnit.MILLISECONDS)?.toMap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using FIrebase Test Lab instead CI emulator
Hmmm, maybe, not sure? 🤔
moving from emulator-based functional test to Robolectric
Hmmm, if I could vote, I would say to NOT making that move to Robolectric. 😊
I agree that it's quite a big change (first of many to the SDK), but one of the reasons for adding functional tests, was to eliminate a need for manual testing. They are as close to the real scenario as possible - only instead of a person tapping buttons, we run SDK functions, and instead of a person validating logs - we have assertions. Do you have some additional scenario in mind that we should test here manually? |
@ParaskP7 heads up - in case of some changes/bugfixes that can be needed for current As soon as all code will be migrated to use Coroutines, I'll merge the long-running branch to |
👋 @wzieba !
💯 but also, IMHO, elevating manual testing after merging this, not before, thus me suggested we still do manual testing on this PR. Still, I do understand were you are coming from. 💯
👍
Nothing comes to mind as I am not having all testing scenarios in my head, I just did some basic manual testing myself and wondered if I covered everything needed. Thus me trying to be on the safe side and asking you for an explicit testing scenario list so that I can be a bit more relaxed with this merge. 😊 |
Oh nice, this kind of makes sense, thanks for the heads-up on that @wzieba ! 👍
👍 |
Description
This PR moves
FlushTimer
class to separate class, rewrites it in Kotlin Coroutines and adds unit tests coverage. Additionally, it adds a functional test that asserts the correct flushing queue logic.To test
Green light from CI should be fine 👍