@@ -12,6 +12,7 @@ import io.sentry.ProfilingTraceData
12
12
import io.sentry.Sentry
13
13
import io.sentry.SentryEvent
14
14
import io.sentry.android.core.SentryAndroidOptions
15
+ import io.sentry.assertEnvelopeItem
15
16
import io.sentry.profilemeasurements.ProfileMeasurement
16
17
import io.sentry.protocol.SentryTransaction
17
18
import org.junit.runner.RunWith
@@ -34,7 +35,7 @@ class EnvelopeTests : BaseUiTest() {
34
35
Sentry .captureMessage(" Message captured during test" )
35
36
36
37
relay.assert {
37
- assertEnvelope {
38
+ assertFirstEnvelope {
38
39
val event: SentryEvent = it.assertItem()
39
40
it.assertNoOtherItems()
40
41
assertTrue(event.message?.formatted == " Message captured during test" )
@@ -53,7 +54,7 @@ class EnvelopeTests : BaseUiTest() {
53
54
54
55
relayIdlingResource.increment()
55
56
IdlingRegistry .getInstance().register(ProfilingSampleActivity .scrollingIdlingResource)
56
- val transaction = Sentry .startTransaction(" e2etests " , " test1" )
57
+ val transaction = Sentry .startTransaction(" profiledTransaction " , " test1" )
57
58
val sampleScenario = launchActivity<ProfilingSampleActivity >()
58
59
swipeList(1 )
59
60
sampleScenario.moveToState(Lifecycle .State .DESTROYED )
@@ -63,21 +64,29 @@ class EnvelopeTests : BaseUiTest() {
63
64
64
65
transaction.finish()
65
66
relay.assert {
66
- assertEnvelope {
67
+ findEnvelope {
68
+ assertEnvelopeItem<SentryTransaction >(it.items.toList()).transaction == " ProfilingSampleActivity"
69
+ }.assert {
67
70
val transactionItem: SentryTransaction = it.assertItem()
68
71
it.assertNoOtherItems()
69
72
assertEquals(" ProfilingSampleActivity" , transactionItem.transaction)
70
73
}
71
- assertEnvelope {
74
+
75
+ findEnvelope {
76
+ assertEnvelopeItem<SentryTransaction >(it.items.toList()).transaction == " profiledTransaction"
77
+ }.assert {
72
78
val transactionItem: SentryTransaction = it.assertItem()
73
79
it.assertNoOtherItems()
74
- assertEquals(" e2etests " , transactionItem.transaction)
80
+ assertEquals(" profiledTransaction " , transactionItem.transaction)
75
81
}
76
- assertEnvelope {
82
+
83
+ findEnvelope {
84
+ assertEnvelopeItem<ProfilingTraceData >(it.items.toList()).transactionName == " profiledTransaction"
85
+ }.assert {
77
86
val profilingTraceData: ProfilingTraceData = it.assertItem()
78
87
it.assertNoOtherItems()
79
88
assertEquals(profilingTraceData.transactionId, transaction.eventId.toString())
80
- assertEquals(" e2etests " , profilingTraceData.transactionName)
89
+ assertEquals(" profiledTransaction " , profilingTraceData.transactionName)
81
90
assertTrue(profilingTraceData.environment.isNotEmpty())
82
91
assertTrue(profilingTraceData.cpuArchitecture.isNotEmpty())
83
92
assertTrue(profilingTraceData.transactions.isNotEmpty())
@@ -127,24 +136,31 @@ class EnvelopeTests : BaseUiTest() {
127
136
transaction3.finish()
128
137
129
138
relay.assert {
130
- assertEnvelope {
139
+ findEnvelope {
140
+ assertEnvelopeItem<SentryTransaction >(it.items.toList()).transaction == " e2etests"
141
+ }.assert {
131
142
val transactionItem: SentryTransaction = it.assertItem()
132
143
it.assertNoOtherItems()
133
144
assertEquals(transaction.eventId.toString(), transactionItem.eventId.toString())
134
145
}
135
- assertEnvelope {
146
+ findEnvelope {
147
+ assertEnvelopeItem<SentryTransaction >(it.items.toList()).transaction == " e2etests1"
148
+ }.assert {
136
149
val transactionItem: SentryTransaction = it.assertItem()
137
150
it.assertNoOtherItems()
138
151
assertEquals(transaction2.eventId.toString(), transactionItem.eventId.toString())
139
152
}
140
- // The profile is sent only in the last transaction envelope
141
- assertEnvelope {
153
+ findEnvelope {
154
+ assertEnvelopeItem<SentryTransaction >(it.items.toList()).transaction == " e2etests2"
155
+ }.assert {
142
156
val transactionItem: SentryTransaction = it.assertItem()
143
157
it.assertNoOtherItems()
144
158
assertEquals(transaction3.eventId.toString(), transactionItem.eventId.toString())
145
159
}
146
- // The profile is sent only in the last transaction envelope
147
- assertEnvelope {
160
+ // The profile is sent in its own envelope
161
+ findEnvelope {
162
+ assertEnvelopeItem<ProfilingTraceData >(it.items.toList()).transactionName == " e2etests2"
163
+ }.assert {
148
164
val profilingTraceData: ProfilingTraceData = it.assertItem()
149
165
it.assertNoOtherItems()
150
166
assertEquals(" e2etests2" , profilingTraceData.transactionName)
@@ -191,7 +207,7 @@ class EnvelopeTests : BaseUiTest() {
191
207
relayIdlingResource.increment()
192
208
relayIdlingResource.increment()
193
209
val profilesDirPath = Sentry .getCurrentHub().options.profilingTracesDirPath
194
- val transaction = Sentry .startTransaction(" e2etests " , " test empty" )
210
+ val transaction = Sentry .startTransaction(" emptyProfileTransaction " , " test empty" )
195
211
196
212
var finished = false
197
213
Thread {
@@ -209,13 +225,15 @@ class EnvelopeTests : BaseUiTest() {
209
225
}
210
226
211
227
relay.assert {
212
- assertEnvelope {
228
+ findEnvelope {
229
+ assertEnvelopeItem<SentryTransaction >(it.items.toList()).transaction == " emptyProfileTransaction"
230
+ }.assert {
213
231
val transactionItem: SentryTransaction = it.assertItem()
214
232
it.assertNoOtherItems()
215
- assertEquals(" e2etests " , transactionItem.transaction)
233
+ assertEquals(" emptyProfileTransaction " , transactionItem.transaction)
216
234
}
217
235
// The profile failed to be sent. Trying to read the envelope from the data transmitted throws an exception
218
- assertFailsWith<IllegalArgumentException > { assertEnvelope {} }
236
+ assertFailsWith<IllegalArgumentException > { assertFirstEnvelope {} }
219
237
assertNoOtherEnvelopes()
220
238
assertNoOtherRequests()
221
239
}
@@ -230,14 +248,16 @@ class EnvelopeTests : BaseUiTest() {
230
248
options.profilesSampleRate = 1.0
231
249
}
232
250
relayIdlingResource.increment()
233
- Sentry .startTransaction(" e2etests " , " testTimeout" )
251
+ Sentry .startTransaction(" timedOutProfile " , " testTimeout" )
234
252
// We don't call transaction.finish() and let the timeout do its job
235
253
236
254
relay.assert {
237
- assertEnvelope {
255
+ findEnvelope {
256
+ assertEnvelopeItem<ProfilingTraceData >(it.items.toList()).transactionName == " timedOutProfile"
257
+ }.assert {
238
258
val profilingTraceData: ProfilingTraceData = it.assertItem()
239
259
it.assertNoOtherItems()
240
- assertEquals(" e2etests " , profilingTraceData.transactionName)
260
+ assertEquals(" timedOutProfile " , profilingTraceData.transactionName)
241
261
assertEquals(ProfilingTraceData .TRUNCATION_REASON_TIMEOUT , profilingTraceData.truncationReason)
242
262
}
243
263
assertNoOtherEnvelopes()
0 commit comments