File tree Expand file tree Collapse file tree
sentry-android-replay/src
main/java/io/sentry/android/replay
test/java/io/sentry/android/replay Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -86,6 +86,11 @@ public class ReplayIntegration(
8686 SentryIntegrationPackageStorage .getInstance()
8787 .addPackage(" maven:io.sentry:sentry-android-replay" , BuildConfig .VERSION_NAME )
8888 }
89+
90+ // Replays recorded by this process. Their folders hold segment videos the transport may still
91+ // read after the replay stopped, so the startup cleanup of previous replays must keep them.
92+ // Shared across instances, because a second SDK init registers a new ReplayIntegration.
93+ val replayIdsOfThisProcess = CopyOnWriteArraySet <String >()
8994 }
9095
9196 // needed for the Java's call site
@@ -139,9 +144,6 @@ public class ReplayIntegration(
139144 private var mainLooperHandler: MainLooperHandler = MainLooperHandler ()
140145 private var gestureRecorderProvider: (() -> GestureRecorder )? = null
141146 private val state = AtomicReference (ReplayState ())
142- // Replays recorded by this process. Their folders hold segment videos the transport may still
143- // read after the replay stopped, so the startup cleanup of previous replays must keep them.
144- private val replayIdsOfThisProcess = CopyOnWriteArraySet <String >()
145147
146148 override fun register (scopes : IScopes , options : SentryOptions ) {
147149 this .options = options
Original file line number Diff line number Diff line change @@ -1295,6 +1295,30 @@ class ReplayIntegrationTest {
12951295 assertFalse(olderReplay.exists())
12961296 }
12971297
1298+ @Test
1299+ fun `second SDK init keeps replays recorded by the first one` () {
1300+ val firstReplayId = SentryId ()
1301+ fixture.options.cacheDirPath = tmpDir.newFolder().absolutePath
1302+ val firstStrategy = mock<CaptureStrategy > { on { currentReplayId }.thenReturn(firstReplayId) }
1303+ val first = fixture.getSut(context, replayCaptureStrategyProvider = { firstStrategy })
1304+ first.register(fixture.scopes, fixture.options)
1305+ first.startBuffering()
1306+ val firstReplay =
1307+ File (fixture.options.cacheDirPath, " replay_$firstReplayId " ).also {
1308+ it.mkdirs()
1309+ File (it, " 0.mp4" ).writeBytes(byteArrayOf(1 , 2 , 3 ))
1310+ }
1311+ first.stop()
1312+ first.close()
1313+
1314+ // a new Sentry.init registers a new integration, which runs the startup cleanup again
1315+ val secondStrategy = mock<CaptureStrategy > { on { currentReplayId }.thenReturn(SentryId ()) }
1316+ val second = fixture.getSut(context, replayCaptureStrategyProvider = { secondStrategy })
1317+ second.register(fixture.scopes, fixture.options)
1318+
1319+ assertTrue(File (firstReplay, " 0.mp4" ).exists())
1320+ }
1321+
12981322 @Test
12991323 fun `delayed startup task does not finalize a replay recorded by this process` () {
13001324 val replayId = SentryId ()
You can’t perform that action at this time.
0 commit comments