Skip to content

Commit 09fb0e4

Browse files
committed
Add SessionCaptureStrategyTest
1 parent eced6ae commit 09fb0e4

4 files changed

Lines changed: 478 additions & 7 deletions

File tree

sentry-android-replay/src/main/java/io/sentry/android/replay/ReplayCache.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public class ReplayCache internal constructor(
294294
}
295295
}
296296

297-
internal fun fromDisk(options: SentryOptions, replayId: SentryId): LastSegmentData? {
297+
internal fun fromDisk(options: SentryOptions, replayId: SentryId, replayCacheProvider: ((replayId: SentryId, recorderConfig: ScreenshotRecorderConfig) -> ReplayCache)? = null): LastSegmentData? {
298298
val replayCacheDir = makeReplayCacheDir(options, replayId)
299299
val lastSegmentFile = File(replayCacheDir, ONGOING_SEGMENT)
300300
if (!lastSegmentFile.exists()) {
@@ -348,7 +348,7 @@ public class ReplayCache internal constructor(
348348
scaleFactorY = 1.0f
349349
)
350350

351-
val cache = ReplayCache(options, replayId, recorderConfig)
351+
val cache = replayCacheProvider?.invoke(replayId, recorderConfig) ?: ReplayCache(options, replayId, recorderConfig)
352352
cache.replayCacheDir?.listFiles { dir, name ->
353353
if (name.endsWith(".jpg")) {
354354
val file = File(dir, name)

sentry-android-replay/src/main/java/io/sentry/android/replay/capture/BaseCaptureStrategy.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ internal abstract class BaseCaptureStrategy(
117117
File(cacheDir).listFiles { dir, name ->
118118
if (name.startsWith("replay_") &&
119119
!name.contains(replayId.toString()) &&
120-
!name.contains(unfinishedReplayId)
120+
!(unfinishedReplayId.isNotBlank() && name.contains(unfinishedReplayId))
121121
) {
122122
FileUtils.deleteRecursively(File(dir, name))
123123
}
@@ -134,15 +134,13 @@ internal abstract class BaseCaptureStrategy(
134134
currentSegment = segmentId
135135
currentReplayId = replayId
136136

137-
// TODO: replace it with dateProvider.currentTimeMillis to also test it
138137
segmentTimestamp = DateUtils.getCurrentDateTime()
139138
replayStartTimestamp.set(dateProvider.currentTimeMillis)
140139

141140
finalizePreviousReplay()
142141
}
143142

144143
override fun resume() {
145-
// TODO: replace it with dateProvider.currentTimeMillis to also test it
146144
segmentTimestamp = DateUtils.getCurrentDateTime()
147145
}
148146

@@ -341,7 +339,7 @@ internal abstract class BaseCaptureStrategy(
341339
}
342340
val breadcrumbs = PersistingScopeObserver.read(options, BREADCRUMBS_FILENAME, List::class.java, Breadcrumb.Deserializer()) as? List<Breadcrumb>
343341

344-
val lastSegment = ReplayCache.fromDisk(options, previousReplayId) ?: return@submitSafely
342+
val lastSegment = ReplayCache.fromDisk(options, previousReplayId, replayCacheProvider) ?: return@submitSafely
345343
val segment = createSegment(
346344
duration = lastSegment.duration,
347345
currentSegmentTimestamp = lastSegment.timestamp,

sentry-android-replay/src/test/java/io/sentry/android/replay/ReplayIntegrationTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import kotlin.test.assertTrue
3636
@RunWith(AndroidJUnit4::class)
3737
@Config(sdk = [26])
3838
class ReplayIntegrationTest {
39-
// write tests for ReplayIntegration with mocked context and other android things
4039
@get:Rule
4140
val tmpDir = TemporaryFolder()
4241

0 commit comments

Comments
 (0)