|
1 | 1 | package io.sentry |
2 | 2 |
|
| 3 | +import com.google.common.truth.Truth.assertThat |
3 | 4 | import io.sentry.SentryLevel.WARNING |
| 5 | +import io.sentry.clientreport.ClientReportTestHelper.Companion.assertClientReport |
4 | 6 | import io.sentry.protocol.Request |
5 | 7 | import io.sentry.protocol.SentryId |
6 | 8 | import io.sentry.protocol.User |
@@ -334,16 +336,44 @@ class ScopeTest { |
334 | 336 | } |
335 | 337 |
|
336 | 338 | @Test |
337 | | - fun `when adding breadcrumb, executeBreadcrumb will be executed and throw, but breadcrumb will be added`() { |
338 | | - val exception = Exception("test") |
| 339 | + fun `when beforeBreadcrumb throws, breadcrumb is dropped without notifying observers`() { |
| 340 | + val observer = mock<IScopeObserver>() |
| 341 | + val options = |
| 342 | + SentryOptions().apply { |
| 343 | + setBeforeBreadcrumb { _, _ -> throw Exception("test") } |
| 344 | + addScopeObserver(observer) |
| 345 | + } |
339 | 346 |
|
340 | | - val options = SentryOptions().apply { setBeforeBreadcrumb { _, _ -> throw exception } } |
| 347 | + val scope = Scope(options) |
| 348 | + val breadcrumb = Breadcrumb() |
| 349 | + scope.addBreadcrumb(breadcrumb) |
| 350 | + |
| 351 | + assertThat(scope.breadcrumbs).isEmpty() |
| 352 | + assertThat(breadcrumb.data).doesNotContainKey("sentry:message") |
| 353 | + verifyNoInteractions(observer) |
| 354 | + assertClientReport(options.clientReportRecorder, emptyList()) |
| 355 | + } |
| 356 | + |
| 357 | + @Test |
| 358 | + fun `when beforeBreadcrumb throws, later breadcrumbs can still be added`() { |
| 359 | + var invocationCount = 0 |
| 360 | + val options = |
| 361 | + SentryOptions().apply { |
| 362 | + setBeforeBreadcrumb { breadcrumb, _ -> |
| 363 | + invocationCount++ |
| 364 | + if (invocationCount == 1) { |
| 365 | + throw Exception("test") |
| 366 | + } |
| 367 | + breadcrumb |
| 368 | + } |
| 369 | + } |
341 | 370 |
|
342 | 371 | val scope = Scope(options) |
343 | | - val actual = Breadcrumb() |
344 | | - scope.addBreadcrumb(actual) |
| 372 | + scope.addBreadcrumb(Breadcrumb("dropped")) |
| 373 | + scope.addBreadcrumb(Breadcrumb("kept")) |
345 | 374 |
|
346 | | - assertEquals("test", actual.data["sentry:message"]) |
| 375 | + assertThat(invocationCount).isEqualTo(2) |
| 376 | + assertThat(scope.breadcrumbs.single().message).isEqualTo("kept") |
347 | 377 | } |
348 | 378 |
|
349 | 379 | @Test |
|
0 commit comments