|
| 1 | +package io.sentry.systemtest |
| 2 | + |
| 3 | +import io.sentry.systemtest.util.TestHelper |
| 4 | +import java.util.concurrent.TimeUnit |
| 5 | +import org.junit.Assert.assertEquals |
| 6 | +import org.junit.Assert.assertTrue |
| 7 | +import org.junit.Before |
| 8 | +import org.junit.Test |
| 9 | + |
| 10 | +class ConsoleApplicationSystemTest { |
| 11 | + lateinit var testHelper: TestHelper |
| 12 | + |
| 13 | + @Before |
| 14 | + fun setup() { |
| 15 | + testHelper = TestHelper("http://localhost:8000") |
| 16 | + testHelper.reset() |
| 17 | + } |
| 18 | + |
| 19 | + @Test |
| 20 | + fun `console application sends expected events when run as JAR`() { |
| 21 | + val jarFile = testHelper.findJar("sentry-samples-console") |
| 22 | + val process = |
| 23 | + testHelper.launch( |
| 24 | + jarFile, |
| 25 | + mapOf( |
| 26 | + "SENTRY_DSN" to testHelper.dsn, |
| 27 | + "SENTRY_TRACES_SAMPLE_RATE" to "1.0", |
| 28 | + "SENTRY_ENABLE_PRETTY_SERIALIZATION_OUTPUT" to "false", |
| 29 | + "SENTRY_DEBUG" to "true", |
| 30 | + ), |
| 31 | + ) |
| 32 | + |
| 33 | + process.waitFor(30, TimeUnit.SECONDS) |
| 34 | + assertEquals(0, process.exitValue()) |
| 35 | + |
| 36 | + // Verify that we received the expected events |
| 37 | + verifyExpectedEvents() |
| 38 | + } |
| 39 | + |
| 40 | + private fun verifyExpectedEvents() { |
| 41 | + // Verify we received a "Fatal message!" event |
| 42 | + testHelper.ensureErrorReceived { event -> |
| 43 | + event.message?.formatted == "Fatal message!" && event.level?.name == "FATAL" |
| 44 | + } |
| 45 | + |
| 46 | + // Verify we received a "Some warning!" event |
| 47 | + testHelper.ensureErrorReceived { event -> |
| 48 | + event.message?.formatted == "Some warning!" && event.level?.name == "WARNING" |
| 49 | + } |
| 50 | + |
| 51 | + // Verify we received the RuntimeException |
| 52 | + testHelper.ensureErrorReceived { event -> |
| 53 | + event.exceptions?.any { ex -> ex.type == "RuntimeException" && ex.value == "Some error!" } == |
| 54 | + true |
| 55 | + } |
| 56 | + |
| 57 | + // Verify we received the detailed event with fingerprint |
| 58 | + testHelper.ensureErrorReceived { event -> |
| 59 | + event.message?.message == "Detailed event" && |
| 60 | + event.fingerprints?.contains("NewClientDebug") == true && |
| 61 | + event.level?.name == "DEBUG" |
| 62 | + } |
| 63 | + |
| 64 | + // Verify we received transaction events |
| 65 | + testHelper.ensureTransactionReceived { transaction, _ -> |
| 66 | + transaction.transaction == "transaction name" && |
| 67 | + transaction.spans?.any { span -> span.op == "child" } == true |
| 68 | + } |
| 69 | + |
| 70 | + // Verify we received the loop messages (should be 10 of them) |
| 71 | + var loopMessageCount = 0 |
| 72 | + try { |
| 73 | + for (i in 0..9) { |
| 74 | + testHelper.ensureErrorReceived { event -> |
| 75 | + val matches = |
| 76 | + event.message?.message?.contains("items we'll wait to flush to Sentry!") == true |
| 77 | + if (matches) loopMessageCount++ |
| 78 | + matches |
| 79 | + } |
| 80 | + } |
| 81 | + } catch (e: Exception) { |
| 82 | + // Some loop messages might be missing, but we should have at least some |
| 83 | + } |
| 84 | + |
| 85 | + assertTrue( |
| 86 | + "Should receive at least 5 loop messages, got $loopMessageCount", |
| 87 | + loopMessageCount >= 5, |
| 88 | + ) |
| 89 | + |
| 90 | + // Verify we have breadcrumbs |
| 91 | + testHelper.ensureErrorReceived { event -> |
| 92 | + event.breadcrumbs?.any { breadcrumb -> |
| 93 | + breadcrumb.message?.contains("Processed by") == true |
| 94 | + } == true |
| 95 | + } |
| 96 | + } |
| 97 | +} |
0 commit comments