@@ -346,6 +346,36 @@ class EnvelopeCacheTest {
346346 assertEquals(sessionExitedWithAbnormal, updatedSession!! .timestamp!! .time)
347347 }
348348
349+ @Test
350+ fun `AbnormalExit hint keeps persisted unhandled session as abnormal` () {
351+ val cache = fixture.getSUT()
352+
353+ val previousSessionFile = EnvelopeCache .getPreviousSessionFile(fixture.options.cacheDirPath!! )
354+ val session = createSession().apply { recordNonTerminatingUnhandledError() }
355+ fixture.options.serializer.serialize(session, previousSessionFile.bufferedWriter())
356+
357+ val envelope = SentryEnvelope .from(fixture.options.serializer, SentryEvent (), null )
358+ val abnormalHint =
359+ object : AbnormalExit {
360+ override fun mechanism (): String = " abnormal_mechanism"
361+
362+ override fun ignoreCurrentThread (): Boolean = false
363+
364+ override fun timestamp (): Long = session.started!! .time + TimeUnit .HOURS .toMillis(1 )
365+ }
366+ val hints = HintUtils .createWithTypeCheckHint(abnormalHint)
367+ cache.storeEnvelope(envelope, hints)
368+
369+ val updatedSession =
370+ fixture.options.serializer.deserialize(
371+ previousSessionFile.bufferedReader(),
372+ Session ::class .java,
373+ )
374+ assertEquals(State .Abnormal , updatedSession!! .status)
375+ assertEquals(" abnormal_mechanism" , updatedSession.abnormalMechanism)
376+ assertTrue(updatedSession.hasNonTerminatingUnhandledError())
377+ }
378+
349379 @Test
350380 fun `when AbnormalExit happened before previous session start, does not mark as abnormal` () {
351381 val cache = fixture.getSUT()
@@ -400,6 +430,29 @@ class EnvelopeCacheTest {
400430 assertEquals(nativeCrashTimestamp, updatedSession.timestamp!! .time)
401431 }
402432
433+ @Test
434+ fun `NativeCrashExit hint keeps persisted unhandled session as crashed` () {
435+ val cache = fixture.getSUT()
436+
437+ val previousSessionFile = EnvelopeCache .getPreviousSessionFile(fixture.options.cacheDirPath!! )
438+ val session = createSession().apply { recordNonTerminatingUnhandledError() }
439+ fixture.options.serializer.serialize(session, previousSessionFile.bufferedWriter())
440+
441+ val nativeCrashTimestamp = session.started!! .time + TimeUnit .HOURS .toMillis(1 )
442+ val envelope = SentryEnvelope .from(fixture.options.serializer, SentryEvent (), null )
443+ val hints = HintUtils .createWithTypeCheckHint(NativeCrashExit { nativeCrashTimestamp })
444+ cache.storeEnvelope(envelope, hints)
445+
446+ val updatedSession =
447+ fixture.options.serializer.deserialize(
448+ previousSessionFile.bufferedReader(),
449+ Session ::class .java,
450+ )
451+ assertEquals(State .Crashed , updatedSession!! .status)
452+ assertEquals(nativeCrashTimestamp, updatedSession.timestamp!! .time)
453+ assertFalse(updatedSession.hasNonTerminatingUnhandledError())
454+ }
455+
403456 @Test
404457 fun `when NativeCrashExit happened before previous session start, does not mark as crashed` () {
405458 val cache = fixture.getSUT()
0 commit comments