Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy RUM raw event creation in event generator methods #2363

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ internal class RumApplicationScopeTest {
val fakeEvents = forge.aList {
forge.anyRumEvent(
excluding = listOf(
RumRawEvent.ApplicationStarted::class.java,
RumRawEvent.SdkInit::class.java
RumRawEvent.ApplicationStarted::class,
RumRawEvent.SdkInit::class
)
)
}
Expand Down Expand Up @@ -428,8 +428,8 @@ internal class RumApplicationScopeTest {
val fakeEvents = forge.aList {
forge.anyRumEvent(
excluding = listOf(
RumRawEvent.ApplicationStarted::class.java,
RumRawEvent.SdkInit::class.java
RumRawEvent.ApplicationStarted::class,
RumRawEvent.SdkInit::class
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import com.datadog.android.rum.internal.domain.Time
import com.datadog.tools.unit.forge.aThrowable
import com.datadog.tools.unit.forge.exhaustiveAttributes
import fr.xgouchet.elmyr.Forge
import java.lang.reflect.Type
import java.net.URL
import java.util.UUID
import kotlin.reflect.KClass

internal fun Forge.interactiveRumRawEvent(): RumRawEvent {
return anElementFrom(
Expand Down Expand Up @@ -168,48 +168,50 @@ internal fun Forge.addCustomTimingEvent(): RumRawEvent.AddCustomTiming {
internal fun Forge.validBackgroundEvent(): RumRawEvent {
return this.anElementFrom(
listOf(
startActionEvent(),
addErrorEvent(),
startResourceEvent()
{ startActionEvent() },
{ addErrorEvent() },
{ startResourceEvent() }
)
)
).invoke()
}

internal fun Forge.invalidBackgroundEvent(): RumRawEvent {
return this.anElementFrom(
listOf(
addLongTaskEvent(),
stopActionEvent(),
stopResourceEvent(),
stopResourceWithErrorEvent(),
stopResourceWithStacktraceEvent(),
addViewLoadingTimeEvent()
{ addLongTaskEvent() },
{ stopActionEvent() },
{ stopResourceEvent() },
{ stopResourceWithErrorEvent() },
{ stopResourceWithStacktraceEvent() },
{ addViewLoadingTimeEvent() }
)
)
}

internal fun Forge.anyRumEvent(excluding: List<Type> = listOf()): RumRawEvent {
val allEvents = listOf(
startViewEvent(),
stopViewEvent(),
startActionEvent(),
stopActionEvent(),
startResourceEvent(),
stopResourceEvent(),
stopResourceWithErrorEvent(),
stopResourceWithStacktraceEvent(),
addErrorEvent(),
addLongTaskEvent(),
addFeatureFlagEvaluationEvent(),
addCustomTimingEvent(),
updatePerformanceMetricEvent(),
addViewLoadingTimeEvent()
).invoke()
}

internal fun Forge.anyRumEvent(excluding: List<KClass<out RumRawEvent>> = listOf()): RumRawEvent {
fun <T : RumRawEvent> strictSameTypePair(key: KClass<T>, value: () -> T) = key to value
val allEventsFactories = mapOf<KClass<out RumRawEvent>, () -> RumRawEvent>(
strictSameTypePair(RumRawEvent.StartView::class, { startViewEvent() }),
strictSameTypePair(RumRawEvent.StopView::class, { stopViewEvent() }),
strictSameTypePair(RumRawEvent.StartAction::class, { startActionEvent() }),
strictSameTypePair(RumRawEvent.StopAction::class, { stopActionEvent() }),
strictSameTypePair(RumRawEvent.StartResource::class, { startResourceEvent() }),
strictSameTypePair(RumRawEvent.StopResource::class, { stopResourceEvent() }),
strictSameTypePair(RumRawEvent.StopResourceWithError::class, { stopResourceWithErrorEvent() }),
strictSameTypePair(RumRawEvent.StopResourceWithStackTrace::class, { stopResourceWithStacktraceEvent() }),
strictSameTypePair(RumRawEvent.AddError::class, { addErrorEvent() }),
strictSameTypePair(RumRawEvent.AddLongTask::class, { addLongTaskEvent() }),
strictSameTypePair(RumRawEvent.AddFeatureFlagEvaluation::class, { addFeatureFlagEvaluationEvent() }),
strictSameTypePair(RumRawEvent.AddCustomTiming::class, { addCustomTimingEvent() }),
strictSameTypePair(RumRawEvent.UpdatePerformanceMetric::class, { updatePerformanceMetricEvent() }),
strictSameTypePair(RumRawEvent.AddViewLoadingTime::class, { addViewLoadingTimeEvent() })
)
return this.anElementFrom(
allEvents.filter {
it.javaClass !in excluding
}
)
allEventsFactories
.filter { !excluding.contains(it.key) }
.values
.toList()
).invoke()
}

internal fun Forge.invalidAppLaunchEvent(): RumRawEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -962,14 +962,14 @@ internal class RumSessionScopeTest {
initializeTestedScope(backgroundTrackingEnabled = false)
val fakeNonInteractionEvent1 = forge.anyRumEvent(
excluding = listOf(
RumRawEvent.StartView::class.java,
RumRawEvent.StartAction::class.java
RumRawEvent.StartView::class,
RumRawEvent.StartAction::class
)
)
val fakeNonInteractionEvent2 = forge.anyRumEvent(
excluding = listOf(
RumRawEvent.StartView::class.java,
RumRawEvent.StartAction::class.java
RumRawEvent.StartView::class,
RumRawEvent.StartAction::class
)
)
testedScope.handleEvent(fakeNonInteractionEvent1, mockWriter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9349,14 +9349,14 @@ internal class RumViewScopeTest {
testedScope.handleEvent(
forge.anyRumEvent(
excluding = listOf(
RumRawEvent.StartView::class.java,
RumRawEvent.StopView::class.java,
RumRawEvent.StartAction::class.java,
RumRawEvent.StopAction::class.java,
RumRawEvent.StartResource::class.java,
RumRawEvent.StopResource::class.java,
RumRawEvent.StopResourceWithError::class.java,
RumRawEvent.StopResourceWithStackTrace::class.java
RumRawEvent.StartView::class,
RumRawEvent.StopView::class,
RumRawEvent.StartAction::class,
RumRawEvent.StopAction::class,
RumRawEvent.StartResource::class,
RumRawEvent.StopResource::class,
RumRawEvent.StopResourceWithError::class,
RumRawEvent.StopResourceWithStackTrace::class
)
),
mockWriter
Expand Down