Skip to content

Commit e72f453

Browse files
authored
Merge pull request #2763 from DataDog/yl/remove-main-thread-post
RUM-10143: Stop posting recorded data item from main thread
2 parents 41b9e16 + b7167aa commit e72f453

File tree

3 files changed

+3
-23
lines changed

3 files changed

+3
-23
lines changed

features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/async/RecordedDataQueueHandler.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ internal class RecordedDataQueueHandler(
9999
* for example if a snapshot failed to traverse the tree).
100100
* If neither of the previous conditions occurs, the loop breaks.
101101
*/
102-
@MainThread
103102
override fun tryToConsumeItems() {
104103
// no need to create a thread if the queue is empty
105104
if (recordedDataQueue.isEmpty()) {

features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/async/RecordedDataQueueRefs.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@
66

77
package com.datadog.android.sessionreplay.internal.async
88

9-
import android.os.Handler
10-
import android.os.Looper
11-
129
/**
1310
* References to the work queue context.
1411
*/
1512
internal data class RecordedDataQueueRefs(
16-
private val recordedDataQueueHandler: RecordedDataQueueHandler,
17-
private val mainThreadHandler: Handler = Handler(Looper.getMainLooper())
13+
private val recordedDataQueueHandler: RecordedDataQueueHandler
1814
) {
1915
// this can only be populated after the snapshot has been created
2016
internal var recordedDataQueueItem: SnapshotRecordedDataQueueItem? = null
@@ -28,9 +24,6 @@ internal data class RecordedDataQueueRefs(
2824
}
2925

3026
internal fun tryToConsumeItem() {
31-
mainThreadHandler.post {
32-
@Suppress("ThreadSafety") // we are in the main thread context
33-
recordedDataQueueHandler.tryToConsumeItems()
34-
}
27+
recordedDataQueueHandler.tryToConsumeItems()
3528
}
3629
}

features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/async/RecordedDataQueueRefsTest.kt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
package com.datadog.android.sessionreplay.internal.async
88

9-
import android.os.Handler
109
import com.datadog.android.sessionreplay.forge.ForgeConfigurator
1110
import fr.xgouchet.elmyr.junit5.ForgeConfiguration
1211
import fr.xgouchet.elmyr.junit5.ForgeExtension
@@ -15,10 +14,8 @@ import org.junit.jupiter.api.Test
1514
import org.junit.jupiter.api.extension.ExtendWith
1615
import org.junit.jupiter.api.extension.Extensions
1716
import org.mockito.Mock
18-
import org.mockito.Mockito.`when`
1917
import org.mockito.junit.jupiter.MockitoExtension
2018
import org.mockito.junit.jupiter.MockitoSettings
21-
import org.mockito.kotlin.any
2219
import org.mockito.kotlin.verify
2320
import org.mockito.quality.Strictness
2421

@@ -37,18 +34,9 @@ internal class RecordedDataQueueRefsTest {
3734
@Mock
3835
lateinit var mockRecordedDataQueueItem: SnapshotRecordedDataQueueItem
3936

40-
@Mock
41-
lateinit var mockHandler: Handler
42-
4337
@BeforeEach
4438
fun setup() {
45-
// make mockHandler execute all runnables immediately
46-
`when`(mockHandler.post(any())).thenAnswer {
47-
(it.arguments[0] as Runnable).run()
48-
true
49-
}
50-
51-
testedDataQueueRefs = RecordedDataQueueRefs(mockDataQueueHandler, mockHandler)
39+
testedDataQueueRefs = RecordedDataQueueRefs(mockDataQueueHandler)
5240
testedDataQueueRefs.recordedDataQueueItem = mockRecordedDataQueueItem
5341
}
5442

0 commit comments

Comments
 (0)