diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumResourceScope.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumResourceScope.kt index a29ebed974..1b7c81fd5b 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumResourceScope.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumResourceScope.kt @@ -176,18 +176,10 @@ internal class RumResourceScope( userExtraAttributes = user.extraInfo ) writer.write(rumEvent) - if (isFailedHttpRequest(statusCode)) { - val errorMessage = ERROR_MSG_FORMAT.format(method, url) - sendError(errorMessage, RumErrorSource.NETWORK, statusCode, null, writer) - } parentScope.handleEvent(RumRawEvent.SentResource(), writer) sent = true } - private fun isFailedHttpRequest(statusCode: Long?): Boolean { - return (statusCode ?: 0) >= HTTP_ERROR_CODE_THRESHOLD - } - private fun resolveResourceProvider(): ResourceEvent.Provider? { return if (firstPartyHostDetector.isFirstPartyUrl(url)) { ResourceEvent.Provider( diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/rum/assertj/ResourceEventAssert.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/rum/assertj/ResourceEventAssert.kt index 297104d12d..8cfe5ca3d5 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/rum/assertj/ResourceEventAssert.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/rum/assertj/ResourceEventAssert.kt @@ -76,6 +76,16 @@ internal class ResourceEventAssert(actual: ResourceEvent) : return this } + fun hasStatusCode(expected: Long?): ResourceEventAssert { + assertThat(actual.resource.statusCode) + .overridingErrorMessage( + "Expected event data to have resource.status_code $expected " + + "but was ${actual.resource.statusCode}" + ) + .isEqualTo(expected) + return this + } + fun hasDurationGreaterThan(upperBound: Long): ResourceEventAssert { assertThat(actual.resource.duration) .overridingErrorMessage( diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumResourceScopeTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumResourceScopeTest.kt index a10cac3fd8..9b159c98f2 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumResourceScopeTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumResourceScopeTest.kt @@ -150,9 +150,8 @@ internal class RumResourceScopeTest { val result = testedScope.handleEvent(mockEvent, mockWriter) // Then - val expectedCallTimes = resolveExpectedCallTimes(statusCode) argumentCaptor { - verify(mockWriter, times(expectedCallTimes)).write(capture()) + verify(mockWriter).write(capture()) assertThat(firstValue) .hasAttributes(expectedAttributes) .hasUserExtraAttributes(fakeUserInfo.extraInfo) @@ -162,6 +161,7 @@ internal class RumResourceScopeTest { hasUrl(fakeUrl) hasMethod(fakeMethod) hasKind(kind) + hasStatusCode(statusCode) hasDurationGreaterThan(TimeUnit.MILLISECONDS.toNanos(500)) hasUserInfo(fakeUserInfo) hasConnectivityInfo(fakeNetworkInfo) @@ -173,29 +173,6 @@ internal class RumResourceScopeTest { hasSpanId(null) doesNotHaveAResourceProvider() } - if (expectedCallTimes > 1) { - assertThat(lastValue) - .hasAttributes(expectedAttributes) - .hasUserExtraAttributes(fakeUserInfo.extraInfo) - .hasErrorData { - hasMessage(RumResourceScope.ERROR_MSG_FORMAT.format(fakeMethod, fakeUrl)) - hasSource(RumErrorSource.NETWORK) - hasStackTrace(null) - isCrash(false) - hasResource(fakeUrl, fakeMethod, statusCode) - hasUserInfo(fakeUserInfo) - hasConnectivityInfo(fakeNetworkInfo) - hasView(fakeParentContext.viewId, fakeParentContext.viewUrl) - hasApplicationId(fakeParentContext.applicationId) - hasSessionId(fakeParentContext.sessionId) - hasActionId(fakeParentContext.actionId) - hasErrorType( - RumResourceScope.ERROR_TYPE_BASED_ON_STATUS_CODE_FORMAT.format( - statusCode - ) - ) - } - } } verify(mockParentScope).handleEvent( isA(), @@ -225,9 +202,8 @@ internal class RumResourceScopeTest { val result = testedScope.handleEvent(mockEvent, mockWriter) // Then - val expectedCallTimes = resolveExpectedCallTimes(statusCode) argumentCaptor { - verify(mockWriter, times(expectedCallTimes)).write(capture()) + verify(mockWriter).write(capture()) assertThat(firstValue) .hasAttributes(expectedAttributes) .hasUserExtraAttributes(fakeUserInfo.extraInfo) @@ -237,6 +213,7 @@ internal class RumResourceScopeTest { hasUrl(fakeUrl) hasMethod(fakeMethod) hasKind(kind) + hasStatusCode(statusCode) hasDurationGreaterThan(TimeUnit.MILLISECONDS.toNanos(500)) hasUserInfo(fakeUserInfo) hasConnectivityInfo(fakeNetworkInfo) @@ -249,29 +226,6 @@ internal class RumResourceScopeTest { hasProviderType(ResourceEvent.ProviderType.FIRST_PARTY) hasProviderDomain(URL(fakeUrl).host) } - if (expectedCallTimes > 1) { - assertThat(lastValue) - .hasAttributes(expectedAttributes) - .hasUserExtraAttributes(fakeUserInfo.extraInfo) - .hasErrorData { - hasMessage(RumResourceScope.ERROR_MSG_FORMAT.format(fakeMethod, fakeUrl)) - hasSource(RumErrorSource.NETWORK) - hasStackTrace(null) - isCrash(false) - hasResource(fakeUrl, fakeMethod, statusCode) - hasUserInfo(fakeUserInfo) - hasConnectivityInfo(fakeNetworkInfo) - hasView(fakeParentContext.viewId, fakeParentContext.viewUrl) - hasApplicationId(fakeParentContext.applicationId) - hasSessionId(fakeParentContext.sessionId) - hasActionId(fakeParentContext.actionId) - hasErrorType( - RumResourceScope.ERROR_TYPE_BASED_ON_STATUS_CODE_FORMAT.format( - statusCode - ) - ) - } - } } verify(mockParentScope).handleEvent( isA(), @@ -311,9 +265,8 @@ internal class RumResourceScopeTest { val result = testedScope.handleEvent(mockEvent, mockWriter) // Then - val expectedCallTimes = resolveExpectedCallTimes(statusCode) argumentCaptor { - verify(mockWriter, times(expectedCallTimes)).write(capture()) + verify(mockWriter).write(capture()) assertThat(firstValue) .hasAttributes(expectedAttributes) .hasUserExtraAttributes(fakeUserInfo.extraInfo) @@ -323,6 +276,7 @@ internal class RumResourceScopeTest { hasUrl(brokenUrl) hasMethod(fakeMethod) hasKind(kind) + hasStatusCode(statusCode) hasDurationGreaterThan(TimeUnit.MILLISECONDS.toNanos(500)) hasUserInfo(fakeUserInfo) hasConnectivityInfo(fakeNetworkInfo) @@ -335,29 +289,6 @@ internal class RumResourceScopeTest { hasProviderType(ResourceEvent.ProviderType.FIRST_PARTY) hasProviderDomain(brokenUrl) } - if (expectedCallTimes > 1) { - assertThat(lastValue) - .hasAttributes(expectedAttributes) - .hasUserExtraAttributes(fakeUserInfo.extraInfo) - .hasErrorData { - hasMessage(RumResourceScope.ERROR_MSG_FORMAT.format(fakeMethod, brokenUrl)) - hasSource(RumErrorSource.NETWORK) - hasStackTrace(null) - isCrash(false) - hasResource(brokenUrl, fakeMethod, statusCode) - hasUserInfo(fakeUserInfo) - hasConnectivityInfo(fakeNetworkInfo) - hasView(fakeParentContext.viewId, fakeParentContext.viewUrl) - hasApplicationId(fakeParentContext.applicationId) - hasSessionId(fakeParentContext.sessionId) - hasActionId(fakeParentContext.actionId) - hasErrorType( - RumResourceScope.ERROR_TYPE_BASED_ON_STATUS_CODE_FORMAT.format( - statusCode - ) - ) - } - } } verify(mockParentScope).handleEvent( isA(), @@ -390,9 +321,8 @@ internal class RumResourceScopeTest { val result = testedScope.handleEvent(mockEvent, mockWriter) // Then - val expectedCallTimes = resolveExpectedCallTimes(statusCode) argumentCaptor { - verify(mockWriter, times(expectedCallTimes)).write(capture()) + verify(mockWriter).write(capture()) assertThat(firstValue) .hasAttributes(expectedAttributes) .hasUserExtraAttributes(fakeUserInfo.extraInfo) @@ -402,6 +332,7 @@ internal class RumResourceScopeTest { hasUrl(fakeUrl) hasMethod(fakeMethod) hasKind(kind) + hasStatusCode(statusCode) hasDurationGreaterThan(TimeUnit.MILLISECONDS.toNanos(500)) hasUserInfo(fakeUserInfo) hasConnectivityInfo(fakeNetworkInfo) @@ -413,29 +344,6 @@ internal class RumResourceScopeTest { hasSpanId(fakeSpanId) doesNotHaveAResourceProvider() } - if (expectedCallTimes > 1) { - assertThat(lastValue) - .hasAttributes(expectedAttributes) - .hasUserExtraAttributes(fakeUserInfo.extraInfo) - .hasErrorData { - hasMessage(RumResourceScope.ERROR_MSG_FORMAT.format(fakeMethod, fakeUrl)) - hasSource(RumErrorSource.NETWORK) - hasStackTrace(null) - isCrash(false) - hasResource(fakeUrl, fakeMethod, statusCode) - hasUserInfo(fakeUserInfo) - hasConnectivityInfo(fakeNetworkInfo) - hasView(fakeParentContext.viewId, fakeParentContext.viewUrl) - hasApplicationId(fakeParentContext.applicationId) - hasSessionId(fakeParentContext.sessionId) - hasActionId(fakeParentContext.actionId) - hasErrorType( - RumResourceScope.ERROR_TYPE_BASED_ON_STATUS_CODE_FORMAT.format( - statusCode - ) - ) - } - } } verify(mockParentScope).handleEvent( isA(), @@ -466,9 +374,8 @@ internal class RumResourceScopeTest { val result = testedScope.handleEvent(mockEvent, mockWriter) // Then - val expectedCallTimes = resolveExpectedCallTimes(statusCode) argumentCaptor { - verify(mockWriter, times(expectedCallTimes)).write(capture()) + verify(mockWriter).write(capture()) assertThat(firstValue) .hasAttributes(expectedAttributes) .hasUserExtraAttributes(fakeUserInfo.extraInfo) @@ -478,6 +385,7 @@ internal class RumResourceScopeTest { hasUrl(fakeUrl) hasMethod(fakeMethod) hasKind(kind) + hasStatusCode(statusCode) hasDurationGreaterThan(TimeUnit.MILLISECONDS.toNanos(500)) hasUserInfo(fakeUserInfo) hasConnectivityInfo(fakeNetworkInfo) @@ -489,29 +397,6 @@ internal class RumResourceScopeTest { hasSpanId(null) doesNotHaveAResourceProvider() } - if (expectedCallTimes > 1) { - assertThat(lastValue) - .hasAttributes(expectedAttributes) - .hasUserExtraAttributes(fakeUserInfo.extraInfo) - .hasErrorData { - hasMessage(RumResourceScope.ERROR_MSG_FORMAT.format(fakeMethod, fakeUrl)) - hasSource(RumErrorSource.NETWORK) - hasStackTrace(null) - isCrash(false) - hasResource(fakeUrl, fakeMethod, statusCode) - hasUserInfo(fakeUserInfo) - hasConnectivityInfo(fakeNetworkInfo) - hasView(fakeParentContext.viewId, fakeParentContext.viewUrl) - hasApplicationId(fakeParentContext.applicationId) - hasSessionId(fakeParentContext.sessionId) - hasActionId(fakeParentContext.actionId) - hasErrorType( - RumResourceScope.ERROR_TYPE_BASED_ON_STATUS_CODE_FORMAT.format( - statusCode - ) - ) - } - } } verify(mockParentScope).handleEvent( isA(), @@ -533,9 +418,8 @@ internal class RumResourceScopeTest { val result = testedScope.handleEvent(mockEvent, mockWriter) // Then - val expectedCallTimes = resolveExpectedCallTimes(statusCode) argumentCaptor { - verify(mockWriter, times(expectedCallTimes)).write(capture()) + verify(mockWriter).write(capture()) assertThat(firstValue) .hasUserExtraAttributes(fakeUserInfo.extraInfo) .hasResourceData { @@ -544,6 +428,7 @@ internal class RumResourceScopeTest { hasUrl(fakeUrl) hasMethod(fakeMethod) hasKind(kind) + hasStatusCode(statusCode) hasDurationGreaterThan(TimeUnit.MILLISECONDS.toNanos(500)) hasUserInfo(fakeUserInfo) hasConnectivityInfo(fakeNetworkInfo) @@ -555,29 +440,6 @@ internal class RumResourceScopeTest { hasSpanId(null) doesNotHaveAResourceProvider() } - if (expectedCallTimes > 1) { - assertThat(lastValue) - .hasAttributes(fakeAttributes) - .hasUserExtraAttributes(fakeUserInfo.extraInfo) - .hasErrorData { - hasMessage(RumResourceScope.ERROR_MSG_FORMAT.format(fakeMethod, fakeUrl)) - hasSource(RumErrorSource.NETWORK) - hasStackTrace(null) - isCrash(false) - hasResource(fakeUrl, fakeMethod, statusCode) - hasUserInfo(fakeUserInfo) - hasConnectivityInfo(fakeNetworkInfo) - hasView(fakeParentContext.viewId, fakeParentContext.viewUrl) - hasApplicationId(fakeParentContext.applicationId) - hasSessionId(fakeParentContext.sessionId) - hasActionId(fakeParentContext.actionId) - hasErrorType( - RumResourceScope.ERROR_TYPE_BASED_ON_STATUS_CODE_FORMAT.format( - statusCode - ) - ) - } - } } verify(mockParentScope).handleEvent( isA(), @@ -588,7 +450,7 @@ internal class RumResourceScopeTest { } @Test - fun `𝕄 send related error event 𝕎 handleEvent(StopResource with error statusCode)`( + fun `𝕄 do not send error event 𝕎 handleEvent(StopResource with error statusCode)`( @Forgery kind: RumResourceKind, @LongForgery(400, 600) statusCode: Long, @LongForgery(0, 1024) size: Long @@ -600,31 +462,23 @@ internal class RumResourceScopeTest { // Then argumentCaptor { - verify(mockWriter, times(2)).write(capture()) - assertThat(lastValue) + verify(mockWriter).write(capture()) + assertThat(firstValue) .hasAttributes(fakeAttributes) .hasUserExtraAttributes(fakeUserInfo.extraInfo) - .hasErrorData { - hasMessage(RumResourceScope.ERROR_MSG_FORMAT.format(fakeMethod, fakeUrl)) - hasSource(RumErrorSource.NETWORK) - hasStackTrace(null) - isCrash(false) - hasResource(fakeUrl, fakeMethod, statusCode) + .hasResourceData { + hasKind(kind) + hasStatusCode(statusCode) hasUserInfo(fakeUserInfo) hasConnectivityInfo(fakeNetworkInfo) hasView(fakeParentContext.viewId, fakeParentContext.viewUrl) hasApplicationId(fakeParentContext.applicationId) hasSessionId(fakeParentContext.sessionId) hasActionId(fakeParentContext.actionId) - hasErrorType( - RumResourceScope.ERROR_TYPE_BASED_ON_STATUS_CODE_FORMAT.format( - statusCode - ) - ) } } verify(mockParentScope).handleEvent( - isA(), + isA(), same(mockWriter) ) verifyNoMoreInteractions(mockWriter) @@ -698,9 +552,8 @@ internal class RumResourceScopeTest { val result = testedScope.handleEvent(mockEvent, mockWriter) // Then - val expectedCallTimes = resolveExpectedCallTimes(statusCode) argumentCaptor { - verify(mockWriter, times(expectedCallTimes)).write(capture()) + verify(mockWriter).write(capture()) assertThat(firstValue) .hasAttributes(expectedAttributes) .hasUserExtraAttributes(fakeUserInfo.extraInfo) @@ -710,6 +563,7 @@ internal class RumResourceScopeTest { hasUrl(fakeUrl) hasMethod(fakeMethod) hasKind(kind) + hasStatusCode(statusCode) hasDurationGreaterThan(TimeUnit.MILLISECONDS.toNanos(500)) hasUserInfo(fakeUserInfo) hasConnectivityInfo(fakeNetworkInfo) @@ -721,29 +575,6 @@ internal class RumResourceScopeTest { hasSpanId(null) doesNotHaveAResourceProvider() } - if (expectedCallTimes > 1) { - assertThat(lastValue) - .hasAttributes(expectedAttributes) - .hasUserExtraAttributes(fakeUserInfo.extraInfo) - .hasErrorData { - hasMessage(RumResourceScope.ERROR_MSG_FORMAT.format(fakeMethod, fakeUrl)) - hasSource(RumErrorSource.NETWORK) - hasStackTrace(null) - isCrash(false) - hasResource(fakeUrl, fakeMethod, statusCode) - hasUserInfo(fakeUserInfo) - hasConnectivityInfo(fakeNetworkInfo) - hasView(fakeParentContext.viewId, fakeParentContext.viewUrl) - hasApplicationId(fakeParentContext.applicationId) - hasSessionId(fakeParentContext.sessionId) - hasActionId(fakeParentContext.actionId) - hasErrorType( - RumResourceScope.ERROR_TYPE_BASED_ON_STATUS_CODE_FORMAT.format( - statusCode - ) - ) - } - } } verify(mockParentScope).handleEvent( isA(), @@ -775,9 +606,8 @@ internal class RumResourceScopeTest { val result = testedScope.handleEvent(mockEvent, mockWriter) // Then - val expectedCallTimes = resolveExpectedCallTimes(statusCode) argumentCaptor { - verify(mockWriter, times(expectedCallTimes)).write(capture()) + verify(mockWriter).write(capture()) assertThat(firstValue) .hasAttributes(expectedAttributes) .hasUserExtraAttributes(fakeUserInfo.extraInfo) @@ -787,6 +617,7 @@ internal class RumResourceScopeTest { hasUrl(fakeUrl) hasMethod(fakeMethod) hasKind(kind) + hasStatusCode(statusCode) hasDurationGreaterThan(TimeUnit.MILLISECONDS.toNanos(500)) hasTiming(timing) hasUserInfo(fakeUserInfo) @@ -799,29 +630,6 @@ internal class RumResourceScopeTest { hasSpanId(null) doesNotHaveAResourceProvider() } - if (expectedCallTimes > 1) { - assertThat(lastValue) - .hasAttributes(expectedAttributes) - .hasUserExtraAttributes(fakeUserInfo.extraInfo) - .hasErrorData { - hasMessage(RumResourceScope.ERROR_MSG_FORMAT.format(fakeMethod, fakeUrl)) - hasSource(RumErrorSource.NETWORK) - hasStackTrace(null) - isCrash(false) - hasResource(fakeUrl, fakeMethod, statusCode) - hasUserInfo(fakeUserInfo) - hasConnectivityInfo(fakeNetworkInfo) - hasView(fakeParentContext.viewId, fakeParentContext.viewUrl) - hasApplicationId(fakeParentContext.applicationId) - hasSessionId(fakeParentContext.sessionId) - hasActionId(fakeParentContext.actionId) - hasErrorType( - RumResourceScope.ERROR_TYPE_BASED_ON_STATUS_CODE_FORMAT.format( - statusCode - ) - ) - } - } } verify(mockParentScope).handleEvent( isA(), @@ -854,9 +662,8 @@ internal class RumResourceScopeTest { val result = testedScope.handleEvent(mockEvent, mockWriter) // Then - val expectedCallTimes = resolveExpectedCallTimes(statusCode) argumentCaptor { - verify(mockWriter, times(expectedCallTimes)).write(capture()) + verify(mockWriter).write(capture()) assertThat(firstValue) .hasAttributes(expectedAttributes) .hasUserExtraAttributes(fakeUserInfo.extraInfo) @@ -866,6 +673,7 @@ internal class RumResourceScopeTest { hasUrl(fakeUrl) hasMethod(fakeMethod) hasKind(kind) + hasStatusCode(statusCode) hasDurationGreaterThan(TimeUnit.MILLISECONDS.toNanos(500)) hasNoTiming() hasUserInfo(fakeUserInfo) @@ -878,29 +686,6 @@ internal class RumResourceScopeTest { hasSpanId(null) doesNotHaveAResourceProvider() } - if (expectedCallTimes > 1) { - assertThat(lastValue) - .hasAttributes(expectedAttributes) - .hasUserExtraAttributes(fakeUserInfo.extraInfo) - .hasErrorData { - hasMessage(RumResourceScope.ERROR_MSG_FORMAT.format(fakeMethod, fakeUrl)) - hasSource(RumErrorSource.NETWORK) - hasStackTrace(null) - isCrash(false) - hasResource(fakeUrl, fakeMethod, statusCode) - hasUserInfo(fakeUserInfo) - hasConnectivityInfo(fakeNetworkInfo) - hasView(fakeParentContext.viewId, fakeParentContext.viewUrl) - hasApplicationId(fakeParentContext.applicationId) - hasSessionId(fakeParentContext.sessionId) - hasActionId(fakeParentContext.actionId) - hasErrorType( - RumResourceScope.ERROR_TYPE_BASED_ON_STATUS_CODE_FORMAT.format( - statusCode - ) - ) - } - } } verify(mockParentScope).handleEvent( isA(), @@ -1253,9 +1038,8 @@ internal class RumResourceScopeTest { mockEvent = RumRawEvent.StopResource(fakeKey, statusCode, size, kind, attributes) val resultStop = testedScope.handleEvent(mockEvent, mockWriter) - val expectedCallTimes = resolveExpectedCallTimes(statusCode) argumentCaptor { - verify(mockWriter, times(expectedCallTimes)).write(capture()) + verify(mockWriter).write(capture()) assertThat(firstValue) .hasAttributes(expectedAttributes) .hasUserExtraAttributes(fakeUserInfo.extraInfo) @@ -1264,6 +1048,7 @@ internal class RumResourceScopeTest { hasUrl(fakeUrl) hasMethod(fakeMethod) hasKind(kind) + hasStatusCode(statusCode) hasDurationGreaterThan(TimeUnit.MILLISECONDS.toNanos(500)) hasUserInfo(fakeUserInfo) hasConnectivityInfo(fakeNetworkInfo) @@ -1273,29 +1058,6 @@ internal class RumResourceScopeTest { hasActionId(fakeParentContext.actionId) doesNotHaveAResourceProvider() } - if (expectedCallTimes > 1) { - assertThat(lastValue) - .hasAttributes(expectedAttributes) - .hasUserExtraAttributes(fakeUserInfo.extraInfo) - .hasErrorData { - hasMessage(RumResourceScope.ERROR_MSG_FORMAT.format(fakeMethod, fakeUrl)) - hasSource(RumErrorSource.NETWORK) - hasStackTrace(null) - isCrash(false) - hasResource(fakeUrl, fakeMethod, statusCode) - hasUserInfo(fakeUserInfo) - hasConnectivityInfo(fakeNetworkInfo) - hasView(fakeParentContext.viewId, fakeParentContext.viewUrl) - hasApplicationId(fakeParentContext.applicationId) - hasSessionId(fakeParentContext.sessionId) - hasActionId(fakeParentContext.actionId) - hasErrorType( - RumResourceScope.ERROR_TYPE_BASED_ON_STATUS_CODE_FORMAT.format( - statusCode - ) - ) - } - } } verify(mockParentScope).handleEvent( isA(), @@ -1327,9 +1089,8 @@ internal class RumResourceScopeTest { mockEvent = RumRawEvent.StopResource(fakeKey, statusCode, size, kind, attributes) val resultStop = testedScope.handleEvent(mockEvent, mockWriter) - val expectedCallTimes = resolveExpectedCallTimes(statusCode) argumentCaptor { - verify(mockWriter, times(expectedCallTimes)).write(capture()) + verify(mockWriter).write(capture()) assertThat(firstValue) .hasAttributes(expectedAttributes) .hasUserExtraAttributes(fakeUserInfo.extraInfo) @@ -1338,6 +1099,7 @@ internal class RumResourceScopeTest { hasUrl(fakeUrl) hasMethod(fakeMethod) hasKind(kind) + hasStatusCode(statusCode) hasDurationGreaterThan(TimeUnit.MILLISECONDS.toNanos(500)) hasUserInfo(fakeUserInfo) hasConnectivityInfo(fakeNetworkInfo) @@ -1347,29 +1109,6 @@ internal class RumResourceScopeTest { hasActionId(fakeParentContext.actionId) doesNotHaveAResourceProvider() } - if (expectedCallTimes > 1) { - assertThat(lastValue) - .hasAttributes(expectedAttributes) - .hasUserExtraAttributes(fakeUserInfo.extraInfo) - .hasErrorData { - hasMessage(RumResourceScope.ERROR_MSG_FORMAT.format(fakeMethod, fakeUrl)) - hasSource(RumErrorSource.NETWORK) - hasStackTrace(null) - isCrash(false) - hasResource(fakeUrl, fakeMethod, statusCode) - hasUserInfo(fakeUserInfo) - hasConnectivityInfo(fakeNetworkInfo) - hasView(fakeParentContext.viewId, fakeParentContext.viewUrl) - hasApplicationId(fakeParentContext.applicationId) - hasSessionId(fakeParentContext.sessionId) - hasActionId(fakeParentContext.actionId) - hasErrorType( - RumResourceScope.ERROR_TYPE_BASED_ON_STATUS_CODE_FORMAT.format( - statusCode - ) - ) - } - } } verify(mockParentScope).handleEvent( isA(), @@ -1402,9 +1141,8 @@ internal class RumResourceScopeTest { mockEvent = RumRawEvent.AddResourceTiming(fakeKey, timing) val resultTiming = testedScope.handleEvent(mockEvent, mockWriter) - val expectedCallTimes = resolveExpectedCallTimes(statusCode) argumentCaptor { - verify(mockWriter, times(expectedCallTimes)).write(capture()) + verify(mockWriter).write(capture()) assertThat(firstValue) .hasAttributes(expectedAttributes) .hasUserExtraAttributes(fakeUserInfo.extraInfo) @@ -1413,6 +1151,7 @@ internal class RumResourceScopeTest { hasUrl(fakeUrl) hasMethod(fakeMethod) hasKind(kind) + hasStatusCode(statusCode) hasDurationGreaterThan(TimeUnit.MILLISECONDS.toNanos(500)) hasTiming(timing) hasUserInfo(fakeUserInfo) @@ -1423,29 +1162,6 @@ internal class RumResourceScopeTest { hasActionId(fakeParentContext.actionId) doesNotHaveAResourceProvider() } - if (expectedCallTimes > 1) { - assertThat(lastValue) - .hasAttributes(expectedAttributes) - .hasUserExtraAttributes(fakeUserInfo.extraInfo) - .hasErrorData { - hasMessage(RumResourceScope.ERROR_MSG_FORMAT.format(fakeMethod, fakeUrl)) - hasSource(RumErrorSource.NETWORK) - hasStackTrace(null) - isCrash(false) - hasResource(fakeUrl, fakeMethod, statusCode) - hasUserInfo(fakeUserInfo) - hasConnectivityInfo(fakeNetworkInfo) - hasView(fakeParentContext.viewId, fakeParentContext.viewUrl) - hasApplicationId(fakeParentContext.applicationId) - hasSessionId(fakeParentContext.sessionId) - hasActionId(fakeParentContext.actionId) - hasErrorType( - RumResourceScope.ERROR_TYPE_BASED_ON_STATUS_CODE_FORMAT.format( - statusCode - ) - ) - } - } } verify(mockParentScope).handleEvent( isA(), @@ -1465,13 +1181,5 @@ internal class RumResourceScopeTest { return event } - private fun resolveExpectedCallTimes(statusCode: Long): Int { - return if (statusCode < RumResourceScope.HTTP_ERROR_CODE_THRESHOLD) { - 1 - } else { - 2 - } - } - // endregion }