Skip to content

Commit 004bf19

Browse files
committed
test hard limit
1 parent a39be4d commit 004bf19

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

sentry/api/sentry.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5034,6 +5034,7 @@ public final class io/sentry/logger/LoggerApi : io/sentry/logger/ILoggerApi {
50345034
public final class io/sentry/logger/LoggerBatchProcessor : io/sentry/logger/ILoggerBatchProcessor {
50355035
public static final field FLUSH_AFTER_MS I
50365036
public static final field MAX_BATCH_SIZE I
5037+
public static final field MAX_QUEUE_SIZE I
50375038
public fun <init> (Lio/sentry/SentryOptions;Lio/sentry/ISentryClient;)V
50385039
public fun add (Lio/sentry/SentryLogEvent;)V
50395040
public fun close (Z)V
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package io.sentry.logger
2+
3+
import io.sentry.ISentryClient
4+
import io.sentry.SentryLogEvent
5+
import io.sentry.SentryLogEvents
6+
import io.sentry.SentryLogLevel
7+
import io.sentry.SentryNanotimeDate
8+
import io.sentry.SentryOptions
9+
import io.sentry.protocol.SentryId
10+
import io.sentry.test.DeferredExecutorService
11+
import io.sentry.test.injectForField
12+
import kotlin.test.Test
13+
import kotlin.test.assertEquals
14+
import kotlin.test.assertFalse
15+
import kotlin.test.assertTrue
16+
import org.mockito.kotlin.argumentCaptor
17+
import org.mockito.kotlin.atLeast
18+
import org.mockito.kotlin.mock
19+
import org.mockito.kotlin.verify
20+
21+
class LoggerBatchProcessorTest {
22+
@Test
23+
fun `drops log events after reaching MAX_QUEUE_SIZE limit`() {
24+
// given
25+
val mockClient = mock<ISentryClient>()
26+
val mockExecutor = DeferredExecutorService()
27+
val options = SentryOptions()
28+
val processor = LoggerBatchProcessor(options, mockClient)
29+
processor.injectForField("executorService", mockExecutor)
30+
31+
for (i in 1..1001) {
32+
val logEvent =
33+
SentryLogEvent(SentryId(), SentryNanotimeDate(), "log message $i", SentryLogLevel.INFO)
34+
processor.add(logEvent)
35+
}
36+
37+
// run twice since a non full batch would be scheduled at the end
38+
mockExecutor.runAll()
39+
mockExecutor.runAll()
40+
41+
// assert that the transport received 1000 log events
42+
val captor = argumentCaptor<SentryLogEvents>()
43+
verify(mockClient, atLeast(1)).captureBatchedLogEvents(captor.capture())
44+
45+
val allCapturedEvents = mutableListOf<SentryLogEvent>()
46+
captor.allValues.forEach { logEvents -> allCapturedEvents.addAll(logEvents.items) }
47+
48+
assertEquals(1000, allCapturedEvents.size)
49+
50+
// assert that log 1001 did not make it but log 1000 did get sent
51+
val log1000Found = allCapturedEvents.any { it.body == "log message 1000" }
52+
val log1001Found = allCapturedEvents.any { it.body == "log message 1001" }
53+
54+
assertTrue(log1000Found, "Log 1000 should have been sent")
55+
assertFalse(log1001Found, "Log 1001 should not have been sent")
56+
}
57+
}

0 commit comments

Comments
 (0)