@@ -2,6 +2,7 @@ package io.sentry
2
2
3
3
import io.sentry.protocol.TransactionNameSource
4
4
import io.sentry.protocol.User
5
+ import io.sentry.util.thread.IMainThreadChecker
5
6
import org.awaitility.kotlin.await
6
7
import org.mockito.kotlin.any
7
8
import org.mockito.kotlin.anyOrNull
@@ -11,12 +12,14 @@ import org.mockito.kotlin.never
11
12
import org.mockito.kotlin.spy
12
13
import org.mockito.kotlin.times
13
14
import org.mockito.kotlin.verify
15
+ import org.mockito.kotlin.whenever
14
16
import java.time.LocalDateTime
15
17
import java.time.ZoneOffset
16
18
import java.util.Date
17
19
import kotlin.test.Test
18
20
import kotlin.test.assertEquals
19
21
import kotlin.test.assertFalse
22
+ import kotlin.test.assertNotEquals
20
23
import kotlin.test.assertNotNull
21
24
import kotlin.test.assertNull
22
25
import kotlin.test.assertSame
@@ -1236,4 +1239,30 @@ class SentryTracerTest {
1236
1239
assertTrue(tracer.isFinished)
1237
1240
verify(fixture.hub).captureTransaction(any(), anyOrNull(), anyOrNull(), anyOrNull())
1238
1241
}
1242
+
1243
+ @Test
1244
+ fun `when a span is launched on the main thread, the thread info should be set correctly` () {
1245
+ val mainThreadChecker = mock<IMainThreadChecker >()
1246
+ whenever(mainThreadChecker.isMainThread).thenReturn(true )
1247
+
1248
+ val tracer = fixture.getSut(optionsConfiguration = { options ->
1249
+ options.mainThreadChecker = mainThreadChecker
1250
+ })
1251
+ val span = tracer.startChild(" span.op" )
1252
+ assertNotNull(span.getData(SpanDataConvention .THREAD_ID ))
1253
+ assertEquals(" main" , span.getData(SpanDataConvention .THREAD_NAME ))
1254
+ }
1255
+
1256
+ @Test
1257
+ fun `when a span is launched on the background thread, the thread info should be set correctly` () {
1258
+ val mainThreadChecker = mock<IMainThreadChecker >()
1259
+ whenever(mainThreadChecker.isMainThread).thenReturn(false )
1260
+
1261
+ val tracer = fixture.getSut(optionsConfiguration = { options ->
1262
+ options.mainThreadChecker = mainThreadChecker
1263
+ })
1264
+ val span = tracer.startChild(" span.op" )
1265
+ assertNotNull(span.getData(SpanDataConvention .THREAD_ID ))
1266
+ assertNotEquals(" main" , span.getData(SpanDataConvention .THREAD_NAME ))
1267
+ }
1239
1268
}
0 commit comments