Skip to content

Commit ddea7d5

Browse files
runningcodeclaude
andcommitted
test(clientreport): Cover both onDiscard restore entry points (JAVA-662)
The two tests asserting that restoring counts from an attached client report does not re-fire onDiscard were named for their setup rather than for what actually differed between them, which made the pair read as an accidental duplicate. Name each for its entry point and share the setup and verifications, so it is clear the property is being pinned for both recordLostEnvelope and recordLostEnvelopeItem. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 35304fc commit ddea7d5

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

sentry/src/test/java/io/sentry/clientreport/ClientReportTest.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,24 @@ class ClientReportTest {
320320
}
321321

322322
@Test
323-
fun `restoring counts from an attached client report does not fire onDiscard again`() {
323+
fun `restoring counts via recordLostEnvelope does not fire onDiscard again`() {
324+
assertRestoringCountsDoesNotFireOnDiscard { recorder, envelope ->
325+
recorder.recordLostEnvelope(DiscardReason.EVENT_PROCESSOR, envelope)
326+
}
327+
}
328+
329+
@Test
330+
fun `restoring counts via recordLostEnvelopeItem does not fire onDiscard again`() {
331+
assertRestoringCountsDoesNotFireOnDiscard { recorder, envelope ->
332+
recorder.recordLostEnvelopeItem(DiscardReason.NETWORK_ERROR, envelope.items.first())
333+
}
334+
}
335+
336+
// Counts restored from an attached client report were already reported once, so replaying them
337+
// must not fire onDiscard a second time. Both public entry points have to hold the property.
338+
private fun assertRestoringCountsDoesNotFireOnDiscard(
339+
recordLost: (ClientReportRecorder, SentryEnvelope) -> Unit
340+
) {
324341
val onDiscardMock = mock<SentryOptions.OnDiscardCallback>()
325342
givenClientReportRecorder { options -> options.onDiscard = onDiscardMock }
326343

@@ -331,7 +348,7 @@ class ClientReportTest {
331348
clientReportRecorder.recordLostEvent(DiscardReason.BEFORE_SEND, DataCategory.Profile)
332349

333350
val envelope = clientReportRecorder.attachReportToEnvelope(testHelper.newEnvelope())
334-
clientReportRecorder.recordLostEnvelope(DiscardReason.EVENT_PROCESSOR, envelope)
351+
recordLost(clientReportRecorder, envelope)
335352

336353
verify(onDiscardMock, times(2))
337354
.execute(DiscardReason.CACHE_OVERFLOW, DataCategory.Attachment, 1)

0 commit comments

Comments
 (0)