Skip to content

Commit 251127d

Browse files
authored
Reuse util classes for System tests (#4236)
* Also use port when checking if a request is made to Sentry DSN * changelog * Add a param to control whether the test script should rebuild before running the tested server * Add system tests for distributed tracing * reuse util classes for system tests * add schema
1 parent a2c3d69 commit 251127d

File tree

117 files changed

+828
-3195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+828
-3195
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ subprojects {
155155
}
156156
}
157157

158-
if (!this.name.contains("sample") && !this.name.contains("integration-tests") && this.name != "sentry-test-support" && this.name != "sentry-compose-helper") {
158+
if (!this.name.contains("sample") && !this.name.contains("integration-tests") && this.name != "sentry-system-test-support" && this.name != "sentry-test-support" && this.name != "sentry-compose-helper") {
159159
apply<DistributionPlugin>()
160160
apply<com.vanniktech.maven.publish.MavenPublishPlugin>()
161161

buildSrc/src/main/java/Config.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ object Config {
7575
val log4j2Core = "org.apache.logging.log4j:log4j-core:$log4j2Version"
7676

7777
val jacksonDatabind = "com.fasterxml.jackson.core:jackson-databind"
78+
val jacksonKotlin = "com.fasterxml.jackson.module:jackson-module-kotlin:2.18.3"
7879

7980
val springBootStarter = "org.springframework.boot:spring-boot-starter:$springBootVersion"
8081
val springBootStarterGraphql = "org.springframework.boot:spring-boot-starter-graphql:$springBootVersion"

codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ coverage:
1616
ignore:
1717
- "**/src/test/*"
1818
- "sentry-android-integration-tests/*"
19+
- "sentry-system-test-support/*"
1920
- "sentry-test-support/*"
2021
- "sentry-samples/*"

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/build.gradle.kts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ plugins {
66
id(Config.BuildPlugins.springDependencyManagement) version Config.BuildPlugins.springDependencyManagementVersion
77
kotlin("jvm")
88
kotlin("plugin.spring") version Config.kotlinVersion
9-
id("com.apollographql.apollo3") version "3.8.2"
109
}
1110

1211
group = "io.sentry.sample.spring-boot-jakarta"
@@ -57,6 +56,7 @@ dependencies {
5756
// database query tracing
5857
implementation(projects.sentryJdbc)
5958
runtimeOnly(Config.TestLibs.hsqldb)
59+
testImplementation(projects.sentrySystemTestSupport)
6060
testImplementation(Config.Libs.springBoot3StarterTest) {
6161
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
6262
}
@@ -103,13 +103,3 @@ tasks.named("test").configure {
103103
excludeTestsMatching("io.sentry.systemtest.*")
104104
}
105105
}
106-
107-
apollo {
108-
service("service") {
109-
srcDir("src/test/graphql")
110-
packageName.set("io.sentry.samples.graphql")
111-
outputDirConnection {
112-
connectToKotlinSourceSet("test")
113-
}
114-
}
115-
}

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/test/kotlin/io/sentry/systemtest/DistributedTracingSystemTest.kt

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package io.sentry.systemtest
22

33
import io.sentry.protocol.SentryId
4-
import io.sentry.samples.spring.boot.jakarta.Person
54
import io.sentry.systemtest.util.TestHelper
65
import org.junit.Before
7-
import org.springframework.http.HttpStatus
86
import kotlin.test.Test
97
import kotlin.test.assertEquals
108
import kotlin.test.assertNotEquals
@@ -25,10 +23,12 @@ class DistributedTracingSystemTest {
2523
val restClient = testHelper.restClient
2624
restClient.getPersonDistributedTracing(
2725
1L,
28-
"$traceId-424cffc8f94feeee-1",
29-
"sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rand=0.456789,sentry-sample_rate=0.5,sentry-sampled=true,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"
26+
mapOf(
27+
"sentry-trace" to "$traceId-424cffc8f94feeee-1",
28+
"baggage" to "sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rand=0.456789,sentry-sample_rate=0.5,sentry-sampled=true,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"
29+
)
3030
)
31-
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, restClient.lastKnownStatusCode)
31+
assertEquals(500, restClient.lastKnownStatusCode)
3232

3333
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
3434
transaction.transaction == "GET /tracing/{id}" &&
@@ -47,10 +47,12 @@ class DistributedTracingSystemTest {
4747
val restClient = testHelper.restClient
4848
restClient.getPersonDistributedTracing(
4949
1L,
50-
"$traceId-424cffc8f94feeee-0",
51-
"sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rand=0.456789,sentry-sample_rate=0.5,sentry-sampled=false,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"
50+
mapOf(
51+
"sentry-trace" to "$traceId-424cffc8f94feeee-0",
52+
"baggage" to "sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rand=0.456789,sentry-sample_rate=0.5,sentry-sampled=false,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"
53+
)
5254
)
53-
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, restClient.lastKnownStatusCode)
55+
assertEquals(500, restClient.lastKnownStatusCode)
5456

5557
testHelper.ensureNoTransactionReceived { transaction, envelopeHeader ->
5658
transaction.transaction == "GET /tracing/{id}"
@@ -67,10 +69,12 @@ class DistributedTracingSystemTest {
6769
val restClient = testHelper.restClient
6870
restClient.getPersonDistributedTracing(
6971
1L,
70-
"$traceId-424cffc8f94feeee-1",
71-
"sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rate=0.5,sentry-sampled=true,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"
72+
mapOf(
73+
"sentry-trace" to "$traceId-424cffc8f94feeee-1",
74+
"baggage" to "sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rate=0.5,sentry-sampled=true,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"
75+
)
7276
)
73-
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, restClient.lastKnownStatusCode)
77+
assertEquals(500, restClient.lastKnownStatusCode)
7478

7579
var sampleRand1: String? = null
7680
var sampleRand2: String? = null
@@ -113,10 +117,12 @@ class DistributedTracingSystemTest {
113117
val restClient = testHelper.restClient
114118
restClient.getPersonDistributedTracing(
115119
1L,
116-
"$traceId-424cffc8f94feeee",
117-
"sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rate=0.5,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"
120+
mapOf(
121+
"sentry-trace" to "$traceId-424cffc8f94feeee",
122+
"baggage" to "sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rate=0.5,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"
123+
)
118124
)
119-
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, restClient.lastKnownStatusCode)
125+
assertEquals(500, restClient.lastKnownStatusCode)
120126

121127
var sampleRate1: String? = null
122128
var sampleRate2: String? = null
@@ -161,10 +167,12 @@ class DistributedTracingSystemTest {
161167
val person = Person("firstA", "lastB")
162168
val returnedPerson = restClient.createPersonDistributedTracing(
163169
person,
164-
"$traceId-424cffc8f94feeee-1",
165-
"sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rand=0.456789,sentry-sample_rate=0.5,sentry-sampled=true,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"
170+
mapOf(
171+
"sentry-trace" to "$traceId-424cffc8f94feeee-1",
172+
"baggage" to "sentry-public_key=502f25099c204a2fbf4cb16edc5975d1,sentry-sample_rand=0.456789,sentry-sample_rate=0.5,sentry-sampled=true,sentry-trace_id=$traceId,sentry-transaction=HTTP%20GET"
173+
)
166174
)
167-
assertEquals(HttpStatus.OK, restClient.lastKnownStatusCode)
175+
assertEquals(200, restClient.lastKnownStatusCode)
168176

169177
assertEquals(person.firstName, returnedPerson!!.firstName)
170178
assertEquals(person.lastName, returnedPerson!!.lastName)

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/test/kotlin/io/sentry/systemtest/PersonSystemTest.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package io.sentry.systemtest
22

3-
import io.sentry.samples.spring.boot.jakarta.Person
43
import io.sentry.systemtest.util.TestHelper
54
import org.junit.Before
6-
import org.springframework.http.HttpStatus
75
import kotlin.test.Test
86
import kotlin.test.assertEquals
97

@@ -21,7 +19,7 @@ class PersonSystemTest {
2119
fun `get person fails`() {
2220
val restClient = testHelper.restClient
2321
restClient.getPerson(1L)
24-
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, restClient.lastKnownStatusCode)
22+
assertEquals(500, restClient.lastKnownStatusCode)
2523

2624
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
2725
testHelper.doesTransactionContainSpanWithOp(transaction, "spanCreatedThroughOtelApi") &&
@@ -34,7 +32,7 @@ class PersonSystemTest {
3432
val restClient = testHelper.restClient
3533
val person = Person("firstA", "lastB")
3634
val returnedPerson = restClient.createPerson(person)
37-
assertEquals(HttpStatus.OK, restClient.lastKnownStatusCode)
35+
assertEquals(200, restClient.lastKnownStatusCode)
3836

3937
assertEquals(person.firstName, returnedPerson!!.firstName)
4038
assertEquals(person.lastName, returnedPerson!!.lastName)

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/test/kotlin/io/sentry/systemtest/TodoSystemTest.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package io.sentry.systemtest
22

33
import io.sentry.systemtest.util.TestHelper
44
import org.junit.Before
5-
import org.springframework.http.HttpStatus
65
import kotlin.test.Test
76
import kotlin.test.assertEquals
87

@@ -20,7 +19,7 @@ class TodoSystemTest {
2019
fun `get todo works`() {
2120
val restClient = testHelper.restClient
2221
restClient.getTodo(1L)
23-
assertEquals(HttpStatus.OK, restClient.lastKnownStatusCode)
22+
assertEquals(200, restClient.lastKnownStatusCode)
2423

2524
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
2625
testHelper.doesTransactionContainSpanWithOp(transaction, "todoSpanOtelApi") &&
@@ -33,7 +32,7 @@ class TodoSystemTest {
3332
fun `get todo webclient works`() {
3433
val restClient = testHelper.restClient
3534
restClient.getTodoWebclient(1L)
36-
assertEquals(HttpStatus.OK, restClient.lastKnownStatusCode)
35+
assertEquals(200, restClient.lastKnownStatusCode)
3736

3837
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
3938
testHelper.doesTransactionContainSpanWithOp(transaction, "http.client")
@@ -44,7 +43,7 @@ class TodoSystemTest {
4443
fun `get todo restclient works`() {
4544
val restClient = testHelper.restClient
4645
restClient.getTodoRestClient(1L)
47-
assertEquals(HttpStatus.OK, restClient.lastKnownStatusCode)
46+
assertEquals(200, restClient.lastKnownStatusCode)
4847

4948
testHelper.ensureTransactionReceived { transaction, envelopeHeader ->
5049
testHelper.doesTransactionContainSpanWithOp(transaction, "todoRestClientSpanOtelApi") &&

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/build.gradle.kts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ plugins {
77
id(Config.BuildPlugins.springDependencyManagement) version Config.BuildPlugins.springDependencyManagementVersion
88
kotlin("jvm")
99
kotlin("plugin.spring") version Config.kotlinVersion
10-
id("com.apollographql.apollo3") version "3.8.2"
1110
}
1211

1312
group = "io.sentry.sample.spring-boot-jakarta"
@@ -58,6 +57,8 @@ dependencies {
5857
// database query tracing
5958
implementation(projects.sentryJdbc)
6059
runtimeOnly(Config.TestLibs.hsqldb)
60+
61+
testImplementation(projects.sentrySystemTestSupport)
6162
testImplementation(Config.Libs.springBoot3StarterTest) {
6263
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
6364
}
@@ -123,13 +124,3 @@ tasks.named("test").configure {
123124
excludeTestsMatching("io.sentry.systemtest.*")
124125
}
125126
}
126-
127-
apollo {
128-
service("service") {
129-
srcDir("src/test/graphql")
130-
packageName.set("io.sentry.samples.graphql")
131-
outputDirConnection {
132-
connectToKotlinSourceSet("test")
133-
}
134-
}
135-
}

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/src/test/graphql/greeting.graphql

Lines changed: 0 additions & 3 deletions
This file was deleted.

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/src/test/graphql/project.graphql

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)