Skip to content

Commit

Permalink
Always resume the replay in lifecycle watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn committed Feb 5, 2025
1 parent 80c68ed commit 480c7b5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import io.sentry.util.AutoClosableReentrantLock;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -21,7 +20,6 @@
final class LifecycleWatcher implements DefaultLifecycleObserver {

private final AtomicLong lastUpdatedSession = new AtomicLong(0L);
private final AtomicBoolean isFreshSession = new AtomicBoolean(false);

private final long sessionIntervalMillis;

Expand Down Expand Up @@ -82,7 +80,6 @@ private void startSession() {
final @Nullable Session currentSession = scope.getSession();
if (currentSession != null && currentSession.getStarted() != null) {
lastUpdatedSession.set(currentSession.getStarted().getTime());
isFreshSession.set(true);
}
}
});
Expand All @@ -94,11 +91,8 @@ private void startSession() {
scopes.startSession();
}
scopes.getOptions().getReplayController().start();
} else if (!isFreshSession.get()) {
// only resume if it's not a fresh session, which has been started in SentryAndroid.init
scopes.getOptions().getReplayController().resume();
}
isFreshSession.set(false);
scopes.getOptions().getReplayController().resume();
this.lastUpdatedSession.set(currentTimeMillis);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class LifecycleWatcherTest {
}

@Test
fun `if the hub has already a fresh session running, doesn't resume replay`() {
fun `if the hub has already a fresh session running, resumes replay to invalidate isManualPause flag`() {
val watcher = fixture.getSUT(
enableAppLifecycleBreadcrumbs = false,
session = Session(
Expand All @@ -276,7 +276,7 @@ class LifecycleWatcherTest {
)

watcher.onStart(fixture.ownerMock)
verify(fixture.replayController, never()).resume()
verify(fixture.replayController).resume()
}

@Test
Expand All @@ -293,7 +293,7 @@ class LifecycleWatcherTest {
verify(fixture.replayController).pause()

watcher.onStart(fixture.ownerMock)
verify(fixture.replayController).resume()
verify(fixture.replayController, times(2)).resume()

watcher.onStop(fixture.ownerMock)
verify(fixture.replayController, timeout(10000)).stop()
Expand Down

0 comments on commit 480c7b5

Please sign in to comment.