From 95d4d33b62dc69a90b2c9f6e960118e247313429 Mon Sep 17 00:00:00 2001 From: bidetofevil Date: Tue, 17 Dec 2024 12:09:02 -0800 Subject: [PATCH] Validate internal error logs sent in resurrection test --- .../internal/delivery/PayloadType.kt | 3 ++ .../features/ResurrectionFeatureTest.kt | 38 ++++++++++++++----- .../EmbracePayloadAssertionInterface.kt | 4 -- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/embrace-android-delivery/src/main/kotlin/io/embrace/android/embracesdk/internal/delivery/PayloadType.kt b/embrace-android-delivery/src/main/kotlin/io/embrace/android/embracesdk/internal/delivery/PayloadType.kt index 97f40c0a18..063327e632 100644 --- a/embrace-android-delivery/src/main/kotlin/io/embrace/android/embracesdk/internal/delivery/PayloadType.kt +++ b/embrace-android-delivery/src/main/kotlin/io/embrace/android/embracesdk/internal/delivery/PayloadType.kt @@ -12,6 +12,7 @@ enum class PayloadType( AEI("sys.exit"), EXCEPTION("sys.exception"), NETWORK_CAPTURE("sys.network_capture"), + INTERNAL_ERROR("sys.internal"), UNKNOWN("unknown"); companion object { @@ -30,6 +31,7 @@ enum class PayloadType( AEI -> "aei" EXCEPTION -> "exception" NETWORK_CAPTURE -> "network" + INTERNAL_ERROR -> "internal" else -> "unknown" } } @@ -45,6 +47,7 @@ enum class PayloadType( "aei" -> AEI "exception" -> EXCEPTION "network" -> NETWORK_CAPTURE + "internal" -> INTERNAL_ERROR else -> UNKNOWN } } diff --git a/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testcases/features/ResurrectionFeatureTest.kt b/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testcases/features/ResurrectionFeatureTest.kt index 2a215dfc68..ca16c93f08 100644 --- a/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testcases/features/ResurrectionFeatureTest.kt +++ b/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testcases/features/ResurrectionFeatureTest.kt @@ -16,11 +16,12 @@ import io.embrace.android.embracesdk.internal.config.remote.RemoteConfig import io.embrace.android.embracesdk.internal.delivery.PayloadType import io.embrace.android.embracesdk.internal.delivery.StoredTelemetryMetadata import io.embrace.android.embracesdk.internal.delivery.SupportedEnvelopeType -import io.embrace.android.embracesdk.internal.logging.InternalErrorType +import io.embrace.android.embracesdk.internal.spans.findAttributeValue import io.embrace.android.embracesdk.testframework.IntegrationTestRule import io.embrace.android.embracesdk.testframework.actions.EmbraceSetupInterface import io.embrace.android.embracesdk.testframework.actions.createStoredNativeCrashData import io.embrace.android.embracesdk.testframework.assertions.getLastLog +import io.opentelemetry.semconv.ExceptionAttributes import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNotNull @@ -122,7 +123,12 @@ internal class ResurrectionFeatureTest { createCrashEnvelope = false, ) testRule.runTest( - instrumentedConfig = FakeInstrumentedConfig(enabledFeatures = FakeEnabledFeatureConfig(nativeCrashCapture = true)), + instrumentedConfig = FakeInstrumentedConfig( + enabledFeatures = FakeEnabledFeatureConfig( + bgActivityCapture = false, + nativeCrashCapture = true + ) + ), setupAction = { setupCachedDataFromNativeCrash(cacheStorageService, crashData = crashData) setupFakeNativeCrash(serializer, crashData) @@ -132,17 +138,31 @@ internal class ResurrectionFeatureTest { }, assertAction = { val session = getSingleSessionEnvelope() - val envelope = getSingleLogEnvelope() - with(envelope) { + val envelopes = getLogEnvelopes(2) + with(envelopes.first()) { assertEquals(session.resource, resource) assertEquals(session.metadata, metadata) + val crash = getLastLog() + assertNativeCrashSent(crash, crashData, testRule.setup.symbols) } - val log = envelope.getLastLog() - assertNativeCrashSent(log, crashData, testRule.setup.symbols) - assertEquals(2, getInternalErrors().size) - assertEquals(InternalErrorType.NATIVE_CRASH_RESURRECTION_ERROR.toString(), getInternalErrors().first().msg) - assertEquals(InternalErrorType.PAYLOAD_STORAGE_FAIL.toString(), getInternalErrors().last().msg) + with(envelopes.last()) { + val errors = checkNotNull(data.logs) + assertEquals(2, errors.size) + with(errors.first()) { + assertEquals( + "Cached native crash envelope data not found", + attributes?.findAttributeValue(ExceptionAttributes.EXCEPTION_MESSAGE.key) + ) + } + + with(errors.last()) { + assertEquals( + "java.io.FileNotFoundException", + attributes?.findAttributeValue(ExceptionAttributes.EXCEPTION_TYPE.key) + ) + } + } } ) } diff --git a/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testframework/actions/EmbracePayloadAssertionInterface.kt b/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testframework/actions/EmbracePayloadAssertionInterface.kt index f875556d79..344838f60a 100644 --- a/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testframework/actions/EmbracePayloadAssertionInterface.kt +++ b/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testframework/actions/EmbracePayloadAssertionInterface.kt @@ -7,7 +7,6 @@ import io.embrace.android.embracesdk.assertions.findSessionSpan import io.embrace.android.embracesdk.assertions.getSessionId import io.embrace.android.embracesdk.assertions.returnIfConditionMet import io.embrace.android.embracesdk.fakes.FakeDeliveryService -import io.embrace.android.embracesdk.fakes.FakeEmbLogger import io.embrace.android.embracesdk.internal.TypeUtils import io.embrace.android.embracesdk.internal.clock.nanosToMillis import io.embrace.android.embracesdk.internal.config.remote.RemoteConfig @@ -53,7 +52,6 @@ internal class EmbracePayloadAssertionInterface( private val deliveryService by lazy { bootstrapper.deliveryModule.deliveryService as FakeDeliveryService } private val serializer by lazy { bootstrapper.initModule.jsonSerializer } - private val logger by lazy { bootstrapper.initModule.logger as FakeEmbLogger } private val deliveryTracer by lazy { checkNotNull(bootstrapper.deliveryModule.deliveryTracer) } @@ -348,8 +346,6 @@ internal class EmbracePayloadAssertionInterface( } } - internal fun getInternalErrors(): List = logger.internalErrorMessages - /** * Retrieves a payload that was stored in the delivery service. */