-
-
Notifications
You must be signed in to change notification settings - Fork 475
Expand file tree
/
Copy pathConsoleApplicationSystemTest.kt
More file actions
114 lines (98 loc) · 3.85 KB
/
Copy pathConsoleApplicationSystemTest.kt
File metadata and controls
114 lines (98 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package io.sentry.systemtest
import io.sentry.protocol.SentryId
import io.sentry.systemtest.util.TestHelper
import java.util.concurrent.TimeUnit
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
class ConsoleApplicationSystemTest {
lateinit var testHelper: TestHelper
@Before
fun setup() {
testHelper = TestHelper("http://localhost:8000")
testHelper.reset()
}
@Test
fun `console application sends expected events when run as JAR`() {
val jarFile = testHelper.findJar("sentry-samples-console")
val process =
testHelper.launch(
jarFile,
mapOf(
"SENTRY_DSN" to testHelper.dsn,
"SENTRY_TRACES_SAMPLE_RATE" to "1.0",
"SENTRY_ENABLE_PRETTY_SERIALIZATION_OUTPUT" to "false",
"SENTRY_DEBUG" to "true",
"SENTRY_PROFILE_SESSION_SAMPLE_RATE" to "1.0",
"SENTRY_PROFILE_LIFECYCLE" to "TRACE",
),
)
process.waitFor(30, TimeUnit.SECONDS)
assertEquals(0, process.exitValue())
// Verify that we received the expected events
verifyExpectedEvents()
}
private fun verifyExpectedEvents() {
var profilerId: SentryId? = null
// Verify we received a "Fatal message!" event
testHelper.ensureErrorReceived { event ->
event.message?.formatted == "Fatal message!" && event.level?.name == "FATAL"
}
// Verify we received a "Some warning!" event
testHelper.ensureErrorReceived { event ->
event.message?.formatted == "Some warning!" && event.level?.name == "WARNING"
}
// Verify we received the RuntimeException
testHelper.ensureErrorReceived { event ->
event.exceptions?.any { ex -> ex.type == "RuntimeException" && ex.value == "Some error!" } ==
true && testHelper.doesEventHaveFlag(event, "my-feature-flag", true)
}
// Verify we received the detailed event with fingerprint
testHelper.ensureErrorReceived { event ->
event.message?.message == "Detailed event" &&
event.fingerprints?.contains("NewClientDebug") == true &&
event.level?.name == "DEBUG"
}
// Verify we received transaction events
testHelper.ensureTransactionReceived { transaction, _ ->
profilerId = transaction.contexts.profile?.profilerId
transaction.transaction == "transaction name" &&
transaction.spans?.any { span -> span.op == "child" } == true
}
testHelper.ensureProfileChunkReceived { profileChunk, envelopeHeader ->
profileChunk.profilerId == profilerId
}
// Verify we received the loop messages (should be 10 of them)
var loopMessageCount = 0
try {
for (i in 0..9) {
testHelper.ensureErrorReceived { event ->
val matches =
event.message?.message?.contains("items we'll wait to flush to Sentry!") == true
if (matches) loopMessageCount++
matches
}
}
} catch (e: Exception) {
// Some loop messages might be missing, but we should have at least some
}
assertTrue(
"Should receive at least 5 loop messages, got $loopMessageCount",
loopMessageCount >= 5,
)
// Verify we have breadcrumbs
testHelper.ensureErrorReceived { event ->
event.breadcrumbs?.any { breadcrumb ->
breadcrumb.message?.contains("Processed by") == true
} == true
}
testHelper.ensureMetricsReceived { metricsEvents, sentryEnvelopeHeader ->
testHelper.doesContainMetric(metricsEvents, "countMetric", "counter", 1.0) &&
testHelper.doesContainMetric(metricsEvents, "gaugeMetric", "gauge", 5.0) &&
testHelper.doesContainMetric(metricsEvents, "distributionMetric", "distribution", 7.0) &&
testHelper.doesMetricHaveAttribute(metricsEvents, "countMetric", "user.type", "admin") &&
testHelper.doesMetricHaveAttribute(metricsEvents, "countMetric", "feature.version", 2)
}
}
}