Skip to content

Commit

Permalink
Merge pull request #1381 from DataDog/jward/session-stop-fix
Browse files Browse the repository at this point in the history
Fix stopped RUMViewManager from being able to start new views.
  • Loading branch information
fuzzybinary authored Apr 13, 2023
2 parents c1fb449 + a4a0770 commit ca81ad7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ internal class RumViewManagerScope(

@WorkerThread
override fun handleEvent(event: RumRawEvent, writer: DataWriter<Any>): RumScope? {
if (!applicationDisplayed && event !is RumRawEvent.StopSession) {
val canDisplayApplication = !stopped && event !is RumRawEvent.StopSession
if (!applicationDisplayed && canDisplayApplication) {
val isForegroundProcess = CoreFeature.processImportance ==
ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
if (isForegroundProcess) {
Expand All @@ -57,7 +58,7 @@ internal class RumViewManagerScope(

delegateToChildren(event, writer)

if (event is RumRawEvent.StartView) {
if (event is RumRawEvent.StartView && !stopped) {
startForegroundView(event)
} else if (event is RumRawEvent.StopSession) {
stopped = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,37 @@ internal class RumViewManagerScopeTest {
assertThat(testedScope.childrenScopes).isEmpty()
}

@Test
fun `M not start a new view W stopped { application not displayed }`(
forge: Forge
) {
// Given
testedScope.handleEvent(RumRawEvent.StopSession(), mockWriter)
val fakeEvent = forge.startViewEvent()

// When
testedScope.handleEvent(fakeEvent, mockWriter)

// Then
assertThat(testedScope.childrenScopes).isEmpty()
}

@Test
fun `M not start a new view W stopped { application displayed }`(
forge: Forge
) {
// Given
testedScope.applicationDisplayed = true
testedScope.handleEvent(RumRawEvent.StopSession(), mockWriter)
val fakeEvent = forge.startViewEvent()

// When
testedScope.handleEvent(fakeEvent, mockWriter)

// Then
assertThat(testedScope.childrenScopes).isEmpty()
}

// endregion

private fun resolveExpectedTimestamp(timestamp: Long): Long {
Expand Down

0 comments on commit ca81ad7

Please sign in to comment.