Skip to content

Commit

Permalink
fixup! RUMM-2335 Add Session Replay hooks into the application lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusc83 committed Jul 25, 2022
1 parent 808031a commit b7158ed
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ internal class SessionReplayFeature(
coreFeature: CoreFeature,
private val sessionReplayCallback:
SessionReplayLifecycleCallback
) :
SdkFeature<Any, Configuration.Feature.SessionReplay>(coreFeature) {
) : SdkFeature<Any, Configuration.Feature.SessionReplay>(coreFeature) {

internal lateinit var appContext: Context
private var isRecording = AtomicBoolean(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.datadog.tools.unit.extensions.TestConfigurationExtension
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.times
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions
import com.nhaarman.mockitokotlin2.verifyZeroInteractions
import fr.xgouchet.elmyr.Forge
import fr.xgouchet.elmyr.junit5.ForgeConfiguration
Expand Down Expand Up @@ -98,7 +99,7 @@ internal class SessionReplayFeatureTest : SdkFeatureTest<Any, Configuration.Feat

// Then
verify(mockSessionReplayLifecycleCallback)
.register(appContext.mockInstance)
.unregisterAndStopRecorders(appContext.mockInstance)
}

@Test
Expand All @@ -119,6 +120,9 @@ internal class SessionReplayFeatureTest : SdkFeatureTest<Any, Configuration.Feat
countDownLatch.await(5, TimeUnit.SECONDS)
verify(mockSessionReplayLifecycleCallback)
.register(appContext.mockInstance)
verify(mockSessionReplayLifecycleCallback)
.unregisterAndStopRecorders(appContext.mockInstance)
verifyNoMoreInteractions(mockSessionReplayLifecycleCallback)
}

@Test
Expand All @@ -133,6 +137,9 @@ internal class SessionReplayFeatureTest : SdkFeatureTest<Any, Configuration.Feat
// Then
verify(mockSessionReplayLifecycleCallback)
.register(appContext.mockInstance)
verify(mockSessionReplayLifecycleCallback)
.unregisterAndStopRecorders(appContext.mockInstance)
verifyNoMoreInteractions(mockSessionReplayLifecycleCallback)
}

@Test
Expand Down Expand Up @@ -170,15 +177,15 @@ internal class SessionReplayFeatureTest : SdkFeatureTest<Any, Configuration.Feat
// When
repeat(3) {
Thread {
testedFeature.stopRecording()
testedFeature.startRecording()
countDownLatch.countDown()
}.run()
}

// Then
countDownLatch.await(5, TimeUnit.SECONDS)
verify(mockSessionReplayLifecycleCallback)
.register(appContext.mockInstance)
verify(mockSessionReplayLifecycleCallback).register(appContext.mockInstance)
verifyNoMoreInteractions(mockSessionReplayLifecycleCallback)
}

@Test
Expand Down
1 change: 0 additions & 1 deletion detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,6 @@ datadog:
- "java.util.WeakHashMap.clear()"
- "java.util.WeakHashMap.remove(android.app.Activity)"
- "java.util.WeakHashMap.remove(kotlin.Any)"
-
# endregion
# region Kotlin Collections
- "kotlin.Array.all(kotlin.Function1)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ import com.datadog.android.sessionreplay.recorder.OrientationChanged
internal interface Processor {
fun process(node: Node)

fun process(orientationChanged: OrientationChanged)
fun process(event: OrientationChanged)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class SnapshotProcessor : Processor {
// TODO RUMM-2271
}

override fun process(orientationChanged: OrientationChanged) {
override fun process(event: OrientationChanged) {
// TODO RUMM-2271
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ internal class RecorderOnDrawListener(
private val processor: Processor,
private val snapshotProducer: SnapshotProducer = SnapshotProducer(),
private val handler: Handler = Handler(Looper.getMainLooper())
) : ViewTreeObserver
.OnDrawListener {
) : ViewTreeObserver.OnDrawListener {
private var currentOrientation = Configuration.ORIENTATION_UNDEFINED
private val trackedActivity: WeakReference<Activity> = WeakReference(activity)

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

@Test
fun `M stop recording all resumed activities W W unregisterAndStopRecorders()`() {
fun `M stop recording all resumed activities W unregisterAndStopRecorders()`() {
// Given
val mockApplication: Application = mock()
val mockActivity1: Activity = mock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ internal class RecorderOnDrawListenerTest {

lateinit var testedListener: RecorderOnDrawListener

@Mock
lateinit var mockActivity: Activity

@Mock
lateinit var mockDecorView: View
lateinit var mockWindow: Window
lateinit var mockResources: Resources
Expand All @@ -75,7 +78,6 @@ internal class RecorderOnDrawListenerTest {

@BeforeEach
fun `set up`(forge: Forge) {
mockDecorView = mock()
whenever(mockDecorView.width).thenReturn(fakeDecorWidth)
whenever(mockDecorView.height).thenReturn(fakeDecorHeight)
mockWindow = mock {
Expand All @@ -91,7 +93,6 @@ internal class RecorderOnDrawListenerTest {
mockResources = mock {
whenever(it.configuration).thenReturn(configuration)
}
mockActivity = mock()
whenever(mockActivity.window).thenReturn(mockWindow)
whenever(mockActivity.resources).thenReturn(mockResources)
testedListener = RecorderOnDrawListener(
Expand Down

0 comments on commit b7158ed

Please sign in to comment.