@@ -452,6 +452,36 @@ class EnvelopeCacheTest {
452452 assertEquals(sessionExitedWithAbnormal, updatedSession!! .timestamp!! .time)
453453 }
454454
455+ @Test
456+ fun `AbnormalExit hint keeps persisted unhandled session as abnormal` () {
457+ val cache = fixture.getSUT()
458+
459+ val previousSessionFile = EnvelopeCache .getPreviousSessionFile(fixture.options.cacheDirPath!! )
460+ val session = createSession().apply { recordNonTerminatingUnhandledError() }
461+ fixture.options.serializer.serialize(session, previousSessionFile.bufferedWriter())
462+
463+ val envelope = SentryEnvelope .from(fixture.options.serializer, SentryEvent (), null )
464+ val abnormalHint =
465+ object : AbnormalExit {
466+ override fun mechanism (): String = " abnormal_mechanism"
467+
468+ override fun ignoreCurrentThread (): Boolean = false
469+
470+ override fun timestamp (): Long = session.started!! .time + TimeUnit .HOURS .toMillis(1 )
471+ }
472+ val hints = HintUtils .createWithTypeCheckHint(abnormalHint)
473+ cache.storeEnvelope(envelope, hints)
474+
475+ val updatedSession =
476+ fixture.options.serializer.deserialize(
477+ previousSessionFile.bufferedReader(),
478+ Session ::class .java,
479+ )
480+ assertEquals(State .Abnormal , updatedSession!! .status)
481+ assertEquals(" abnormal_mechanism" , updatedSession.abnormalMechanism)
482+ assertTrue(updatedSession.hasNonTerminatingUnhandledError())
483+ }
484+
455485 @Test
456486 fun `when AbnormalExit happened before previous session start, does not mark as abnormal` () {
457487 val cache = fixture.getSUT()
@@ -506,6 +536,29 @@ class EnvelopeCacheTest {
506536 assertEquals(nativeCrashTimestamp, updatedSession.timestamp!! .time)
507537 }
508538
539+ @Test
540+ fun `NativeCrashExit hint keeps persisted unhandled session as crashed` () {
541+ val cache = fixture.getSUT()
542+
543+ val previousSessionFile = EnvelopeCache .getPreviousSessionFile(fixture.options.cacheDirPath!! )
544+ val session = createSession().apply { recordNonTerminatingUnhandledError() }
545+ fixture.options.serializer.serialize(session, previousSessionFile.bufferedWriter())
546+
547+ val nativeCrashTimestamp = session.started!! .time + TimeUnit .HOURS .toMillis(1 )
548+ val envelope = SentryEnvelope .from(fixture.options.serializer, SentryEvent (), null )
549+ val hints = HintUtils .createWithTypeCheckHint(NativeCrashExit { nativeCrashTimestamp })
550+ cache.storeEnvelope(envelope, hints)
551+
552+ val updatedSession =
553+ fixture.options.serializer.deserialize(
554+ previousSessionFile.bufferedReader(),
555+ Session ::class .java,
556+ )
557+ assertEquals(State .Crashed , updatedSession!! .status)
558+ assertEquals(nativeCrashTimestamp, updatedSession.timestamp!! .time)
559+ assertFalse(updatedSession.hasNonTerminatingUnhandledError())
560+ }
561+
509562 @Test
510563 fun `when NativeCrashExit happened before previous session start, does not mark as crashed` () {
511564 val cache = fixture.getSUT()
0 commit comments