|
1 | 1 | package io.sentry |
2 | 2 |
|
3 | 3 | import io.sentry.Scope.IWithPropagationContext |
| 4 | +import io.sentry.Session.State.Crashed |
4 | 5 | import io.sentry.clientreport.ClientReportTestHelper.Companion.assertClientReport |
5 | 6 | import io.sentry.clientreport.DiscardReason |
6 | 7 | import io.sentry.clientreport.DiscardedEvent |
@@ -953,6 +954,21 @@ class SentryClientTest { |
953 | 954 | } |
954 | 955 | } |
955 | 956 |
|
| 957 | + @Test |
| 958 | + fun `When event is non handled, end the session`() { |
| 959 | + val scope = Scope(fixture.sentryOptions) |
| 960 | + scope.startSession() |
| 961 | + |
| 962 | + val event = SentryEvent().apply { |
| 963 | + exceptions = createNonHandledException() |
| 964 | + } |
| 965 | + fixture.getSut().updateSessionData(event, Hint(), scope) |
| 966 | + scope.withSession { |
| 967 | + assertEquals(Session.State.Crashed, it!!.status) |
| 968 | + assertNotNull(it.duration) |
| 969 | + } |
| 970 | + } |
| 971 | + |
956 | 972 | @Test |
957 | 973 | fun `When event is handled, keep level as it is`() { |
958 | 974 | val scope = Scope(fixture.sentryOptions) |
@@ -1137,6 +1153,28 @@ class SentryClientTest { |
1137 | 1153 | } |
1138 | 1154 | } |
1139 | 1155 |
|
| 1156 | + @Test |
| 1157 | + fun `when session is in terminal state, does not send session update`() { |
| 1158 | + val sut = fixture.getSut() |
| 1159 | + |
| 1160 | + val event = SentryEvent().apply { |
| 1161 | + exceptions = createNonHandledException() |
| 1162 | + } |
| 1163 | + val scope = Scope(fixture.sentryOptions) |
| 1164 | + val sessionPair = scope.startSession() |
| 1165 | + scope.withSession { it!!.update(Crashed, null, false) } |
| 1166 | + |
| 1167 | + assertNotNull(sessionPair) { |
| 1168 | + sut.captureEvent(event, scope, null) |
| 1169 | + verify(fixture.transport).send( |
| 1170 | + check { |
| 1171 | + assertNull(it.items.find { item -> item.header.type == SentryItemType.Session }) |
| 1172 | + }, |
| 1173 | + anyOrNull() |
| 1174 | + ) |
| 1175 | + } |
| 1176 | + } |
| 1177 | + |
1140 | 1178 | @Test |
1141 | 1179 | fun `when contexts property is set on the event, property from scope contexts is not applied`() { |
1142 | 1180 | val sut = fixture.getSut() |
|
0 commit comments