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: move session-specific logic to Timeline #89

Merged
merged 1 commit into from
Oct 28, 2022

Conversation

falconandy
Copy link
Contributor

Summary

All session-related logic is extracted to new Timeline class.

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?: No

@@ -119,6 +119,8 @@ class AmplitudeTest {
event.eventType = "test event"
amplitude?.track(event)
advanceUntilIdle()
Thread.sleep(100)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this be stable enough for the tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. I can increment it to something like 500 but it will increase test duration.
  2. I would use more stable ways (something like ???.await()) but I am not sure what is better/possible to use in Kotlin and do not add notable memory/cpu overhead.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't believe increasing sleep time is a good option. Not sure if @justin-fiedler or @bgiori know some better ways to mock this in tests in Kotlin though. If not, it maybe fine if you run it several times on local and this test always passes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I ran the tests with Thread.sleep many times locally and they always pass

inForeground = true

val dummySessionStartEvent = BaseEvent()
dummySessionStartEvent.eventType = START_SESSION_EVENT
Copy link
Contributor

Choose a reason for hiding this comment

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

So we always trigger this and decide later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. To avoid any data race issues, all logic is in Timeout now

private suspend fun processEventMessage(message: EventQueueMessage) {
val event = message.event
var sessionEvents: Iterable<BaseEvent>? = null
val eventTimestamp = event.timestamp!!
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe other event timestamp is bind later in process plugins

Copy link
Contributor Author

@falconandy falconandy Oct 26, 2022

Choose a reason for hiding this comment

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

Not sure what you mean. I believe, timestamps should be assigned as soon as possible to have actual live values. Now it is here: https://github.com/amplitude/Amplitude-Kotlin/blob/DXOC-297-DiskReadViolation-in-strict-mode/core/src/main/java/com/amplitude/core/Amplitude.kt#L328.
Other code does fallback assignments like:

event.timestamp ?: let {
    event.timestamp = System.currentTimeMillis()
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, so this is added to cover this. I was worried if this could raiser exceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

processEventMessage is invoked only for items from eventMessageChannel
https://github.com/amplitude/Amplitude-Kotlin/blob/DXOC-297-DiskReadViolation-in-strict-mode/android/src/main/java/com/amplitude/android/Timeline.kt#L25
the only way to add items to eventMessageChannel is process function
https://github.com/amplitude/Amplitude-Kotlin/blob/DXOC-297-DiskReadViolation-in-strict-mode/android/src/main/java/com/amplitude/android/Timeline.kt#L34
here incomingEvent.timestamp = System.currentTimeMillis() exists to be ensure to have non-null timestamp

@qingzhuozhen qingzhuozhen merged commit b353b8c into main Oct 28, 2022
@qingzhuozhen qingzhuozhen deleted the DXOC-297-DiskReadViolation-in-strict-mode branch October 28, 2022 04:31
github-actions bot pushed a commit that referenced this pull request Oct 28, 2022
## [1.4.7](v1.4.6...v1.4.7) (2022-10-28)

### Bug Fixes

* move session-specific logic to Timeline ([#89](#89)) ([b353b8c](b353b8c))
@github-actions
Copy link

🎉 This PR is included in version 1.4.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants