Skip to content

Commit 49b1699

Browse files
committed
More tests
1 parent 0bb6886 commit 49b1699

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

sentry/src/test/java/io/sentry/HubTest.kt

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ import java.io.File
3131
import java.nio.file.Files
3232
import java.util.Queue
3333
import java.util.UUID
34+
import java.util.concurrent.atomic.AtomicReference
3435
import kotlin.test.AfterTest
3536
import kotlin.test.BeforeTest
3637
import kotlin.test.Test
3738
import kotlin.test.assertEquals
3839
import kotlin.test.assertFailsWith
3940
import kotlin.test.assertFalse
41+
import kotlin.test.assertNotEquals
4042
import kotlin.test.assertNotNull
4143
import kotlin.test.assertNull
4244
import kotlin.test.assertTrue
@@ -1725,6 +1727,79 @@ class HubTest {
17251727
verify(hub).reportFullyDisplayed()
17261728
}
17271729

1730+
@Test
1731+
fun `continueTrace creates propagation context from headers and returns transaction context if performance enabled`() {
1732+
val hub = generateHub()
1733+
val traceId = SentryId()
1734+
val parentSpanId = SpanId()
1735+
val transactionContext = hub.continueTrace("$traceId-$parentSpanId-1", listOf("sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rate=1,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"))
1736+
1737+
hub.configureScope { scope ->
1738+
assertEquals(traceId, scope.propagationContext.traceId)
1739+
assertEquals(parentSpanId, scope.propagationContext.parentSpanId)
1740+
}
1741+
1742+
assertEquals(traceId, transactionContext!!.traceId)
1743+
assertEquals(parentSpanId, transactionContext!!.parentSpanId)
1744+
}
1745+
1746+
@Test
1747+
fun `continueTrace creates new propagation context if header invalid and returns transaction context if performance enabled`() {
1748+
val hub = generateHub()
1749+
val traceId = SentryId()
1750+
var propagationContextHolder = AtomicReference<PropagationContext>()
1751+
1752+
hub.configureScope { propagationContextHolder.set(it.propagationContext) }
1753+
val propagationContextAtStart = propagationContextHolder.get()!!
1754+
1755+
val transactionContext = hub.continueTrace("invalid", listOf("sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rate=1,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"))
1756+
1757+
hub.configureScope { scope ->
1758+
assertNotEquals(propagationContextAtStart.traceId, scope.propagationContext.traceId)
1759+
assertNotEquals(propagationContextAtStart.parentSpanId, scope.propagationContext.parentSpanId)
1760+
assertNotEquals(propagationContextAtStart.spanId, scope.propagationContext.spanId)
1761+
1762+
assertEquals(scope.propagationContext.traceId, transactionContext!!.traceId)
1763+
assertEquals(scope.propagationContext.parentSpanId, transactionContext!!.parentSpanId)
1764+
assertEquals(scope.propagationContext.spanId, transactionContext!!.spanId)
1765+
}
1766+
}
1767+
1768+
@Test
1769+
fun `continueTrace creates propagation context from headers and returns null if performance disabled`() {
1770+
val hub = generateHub { it.enableTracing = false }
1771+
val traceId = SentryId()
1772+
val parentSpanId = SpanId()
1773+
val transactionContext = hub.continueTrace("$traceId-$parentSpanId-1", listOf("sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rate=1,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"))
1774+
1775+
hub.configureScope { scope ->
1776+
assertEquals(traceId, scope.propagationContext.traceId)
1777+
assertEquals(parentSpanId, scope.propagationContext.parentSpanId)
1778+
}
1779+
1780+
assertNull(transactionContext)
1781+
}
1782+
1783+
@Test
1784+
fun `continueTrace creates new propagation context if header invalid and returns null if performance disabled`() {
1785+
val hub = generateHub { it.enableTracing = false }
1786+
val traceId = SentryId()
1787+
var propagationContextHolder = AtomicReference<PropagationContext>()
1788+
1789+
hub.configureScope { propagationContextHolder.set(it.propagationContext) }
1790+
val propagationContextAtStart = propagationContextHolder.get()!!
1791+
1792+
val transactionContext = hub.continueTrace("invalid", listOf("sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rate=1,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"))
1793+
1794+
hub.configureScope { scope ->
1795+
assertNotEquals(propagationContextAtStart.traceId, scope.propagationContext.traceId)
1796+
assertNotEquals(propagationContextAtStart.parentSpanId, scope.propagationContext.parentSpanId)
1797+
assertNotEquals(propagationContextAtStart.spanId, scope.propagationContext.spanId)
1798+
}
1799+
1800+
assertNull(transactionContext)
1801+
}
1802+
17281803
private val dsnTest = "https://[email protected]/proj"
17291804

17301805
private fun generateHub(optionsConfiguration: Sentry.OptionsConfiguration<SentryOptions>? = null): IHub {

0 commit comments

Comments
 (0)