Skip to content

Commit

Permalink
Merge pull request #1716 from DataDog/xgouchet/RUM-2127/3_read_synthe…
Browse files Browse the repository at this point in the history
…tics_info

(3/9) RUM-2127 store the synthetics test info in the RUM Context
  • Loading branch information
xgouchet committed Nov 16, 2023
2 parents 13a0f92 + a366d7e commit 50e6072
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ internal class RumApplicationScope(
private val appStartTimeProvider: AppStartTimeProvider = DefaultAppStartTimeProvider()
) : RumScope, RumViewChangedListener {

private val rumContext = RumContext(applicationId = applicationId)
private var rumContext = RumContext(applicationId = applicationId)

internal val childScopes: MutableList<RumScope> = mutableListOf(
RumSessionScope(
this,
Expand Down Expand Up @@ -71,6 +72,13 @@ internal class RumApplicationScope(
event: RumRawEvent,
writer: DataWriter<Any>
): RumScope {
if (event is RumRawEvent.SetSyntheticsTestAttribute) {
rumContext = rumContext.copy(
syntheticsTestId = event.testId,
syntheticsResultId = event.resultId
)
}

val isInteraction = (event is RumRawEvent.StartView) || (event is RumRawEvent.StartAction)
if (activeSession == null && isInteraction) {
startNewSession(event, writer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,39 @@ internal class RumApplicationScopeTest {
}

@Test
fun `always returns the same applicationId`() {
fun `M always return the same applicationId W getRumContext()`() {
val context = testedScope.getRumContext()

assertThat(context.applicationId).isEqualTo(fakeApplicationId)
}

@Test
fun `M return null synthetics info W getRumContext()`() {
val context = testedScope.getRumContext()

assertThat(context.syntheticsTestId).isNull()
assertThat(context.syntheticsResultId).isNull()
}

@Test
fun `M return synthetics test attributes W handleEvent() + getRumContext()`(
@StringForgery fakeTestId: String,
@StringForgery fakeResultId: String
) {
// Given
val event = RumRawEvent.SetSyntheticsTestAttribute(fakeTestId, fakeResultId)

// When
val result = testedScope.handleEvent(event, mockWriter)
val context = testedScope.getRumContext()

// Then
assertThat(result).isSameAs(testedScope)
assertThat(context.syntheticsTestId).isEqualTo(fakeTestId)
assertThat(context.syntheticsResultId).isEqualTo(fakeResultId)
verifyNoInteractions(mockWriter)
}

@Test
fun `M return true W isActive()`() {
val isActive = testedScope.isActive()
Expand Down

0 comments on commit 50e6072

Please sign in to comment.