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

Preserve moments across session boundaries #541

Merged
merged 1 commit into from
Mar 12, 2024

Conversation

fractalwrench
Copy link
Contributor

Goal

Preserves moments across session boundaries if they are considered 'active' (i.e. they have not ended yet). The current implementation simply cleared all the events in our collections; however, it does not seem this behavior was ever hooked up properly until the recent SessionOrchestrator refactor. This meant that moments would be cleared when the session boundary was transitioned - which happened frequently for the app startup moment.

Testing

Added integration + unit test coverage.

@fractalwrench fractalwrench requested a review from a team as a code owner March 11, 2024 12:12
Copy link

codecov bot commented Mar 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.80%. Comparing base (fb350b3) to head (8191745).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #541      +/-   ##
==========================================
+ Coverage   79.73%   79.80%   +0.07%     
==========================================
  Files         409      409              
  Lines       10938    10933       -5     
  Branches     1614     1614              
==========================================
+ Hits         8721     8725       +4     
+ Misses       1569     1564       -5     
+ Partials      648      644       -4     
Files Coverage Δ
...ce/android/embracesdk/event/EmbraceEventService.kt 89.51% <100.00%> (-0.25%) ⬇️
...bracesdk/session/message/PayloadMessageCollator.kt 95.40% <100.00%> (-0.11%) ⬇️

... and 3 files with indirect coverage changes

@@ -54,8 +52,7 @@ internal class EmbraceEventService(
/**
* Timeseries of event IDs, keyed on the start time of the event.
*/
private val eventIds: NavigableMap<Long, String> = ConcurrentSkipListMap()
private val eventIdsCache = CacheableValue<List<String>> { eventIds.size }
private val eventIds = ConcurrentLinkedQueue<String>()
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious, why a queue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted a collection that can be concurrently modified, had reasonable insertion time, and didn't get copied every time (like CopyOnWriteArrayList) as many writes but few reads are expected here.

fakeClock.setCurrentTime(fakeClock.now() + 1L)
assertEquals(4, eventService.findEventIdsForSession(sessionBeginTime, fakeClock.now()).size)
}

@Test
fun `verify close clears the existing events`() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we could remove this test and just call close on the test below. Or maybe improve the naming on this one because "existing events" is a bit ambiguous.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough - removed the old test case.

Copy link
Contributor

@priettt priettt left a comment

Choose a reason for hiding this comment

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

LGTM! Love the tests :)

eventIds.clear()
activeEvents.clear()
logDeveloper("EmbraceEventService", "collections cleaned")
val activeEventIds = activeEvents.values.map { it.event.eventId }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does the active moments list get updated on timeout?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, the EventDescription contains a callback to endEvent that is invoked on the timeout. The item is removed from the collection at that point

@fractalwrench fractalwrench merged commit 1595f6b into master Mar 12, 2024
4 checks passed
@fractalwrench fractalwrench deleted the fix-moment-boundary branch March 12, 2024 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants