Skip to content

Commit

Permalink
Validate internal error logs sent in resurrection test
Browse files Browse the repository at this point in the history
  • Loading branch information
bidetofevil committed Dec 17, 2024
1 parent 14b7d41 commit 95d4d33
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -30,6 +31,7 @@ enum class PayloadType(
AEI -> "aei"
EXCEPTION -> "exception"
NETWORK_CAPTURE -> "network"
INTERNAL_ERROR -> "internal"
else -> "unknown"
}
}
Expand All @@ -45,6 +47,7 @@ enum class PayloadType(
"aei" -> AEI
"exception" -> EXCEPTION
"network" -> NETWORK_CAPTURE
"internal" -> INTERNAL_ERROR

Check warning on line 50 in embrace-android-delivery/src/main/kotlin/io/embrace/android/embracesdk/internal/delivery/PayloadType.kt

View check run for this annotation

Codecov / codecov/patch

embrace-android-delivery/src/main/kotlin/io/embrace/android/embracesdk/internal/delivery/PayloadType.kt#L50

Added line #L50 was not covered by tests
else -> UNKNOWN
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
)
}
}
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -348,8 +346,6 @@ internal class EmbracePayloadAssertionInterface(
}
}

internal fun getInternalErrors(): List<FakeEmbLogger.LogMessage> = logger.internalErrorMessages

/**
* Retrieves a payload that was stored in the delivery service.
*/
Expand Down

0 comments on commit 95d4d33

Please sign in to comment.