@@ -214,6 +214,35 @@ class EnvelopeCacheTest {
214214 assertThat(previousSessionFile.exists()).isFalse()
215215 }
216216
217+ @Test
218+ fun `failed persist stops the delayed same SID SessionStart from being skipped` () {
219+ val cache = fixture.getSUT()
220+ val sid = SentryUUID .generateSentryId()
221+ val currentSessionFile = EnvelopeCache .getCurrentSessionFile(fixture.options.cacheDirPath!! )
222+ val newerSession = createSession(sessionId = sid)
223+ newerSession.recordNonTerminatingUnhandledError()
224+ cache.persistCurrentSession(newerSession)
225+
226+ // a directory where the session file belongs makes the write fail
227+ assertTrue(currentSessionFile.delete())
228+ assertTrue(currentSessionFile.mkdir())
229+ cache.persistCurrentSession(newerSession)
230+ assertTrue(currentSessionFile.delete())
231+
232+ val delayedStart = createSession(sessionId = sid)
233+ val envelope = SentryEnvelope .from(fixture.options.serializer, delayedStart, null )
234+ cache.storeEnvelope(envelope, HintUtils .createWithTypeCheckHint(SessionStartHint ()))
235+
236+ val persistedSession =
237+ fixture.options.serializer.deserialize(
238+ currentSessionFile.bufferedReader(),
239+ Session ::class .java,
240+ )!!
241+ assertThat(persistedSession.sessionId).isEqualTo(sid)
242+ assertThat(persistedSession.hasNonTerminatingUnhandledError()).isFalse()
243+ assertThat(persistedSession.errorCount()).isEqualTo(0 )
244+ }
245+
217246 @Test
218247 fun `null SIDs on SessionStart rotate instead of preserving as same session` () {
219248 val cache = fixture.getSUT()
0 commit comments