Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ retrofit = "2.9.0"
slf4j = "1.7.30"
springboot2 = "2.7.18"
springboot3 = "3.5.0"
springboot4 = "4.0.0-M3"
springboot4 = "4.0.0-RC1"
# Android
targetSdk = "34"
compileSdk = "34"
Expand Down Expand Up @@ -165,6 +165,7 @@ springboot3-starter-security = { module = "org.springframework.boot:spring-boot-
springboot3-starter-jdbc = { module = "org.springframework.boot:spring-boot-starter-jdbc", version.ref = "springboot3" }
springboot3-starter-actuator = { module = "org.springframework.boot:spring-boot-starter-actuator", version.ref = "springboot3" }
springboot4-otel = { module = "io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter", version.ref = "otelInstrumentation" }
springboot4-resttestclient = { module = "org.springframework.boot:spring-boot-resttestclient", version.ref = "springboot4" }
springboot4-starter = { module = "org.springframework.boot:spring-boot-starter", version.ref = "springboot4" }
springboot4-starter-graphql = { module = "org.springframework.boot:spring-boot-starter-graphql", version.ref = "springboot4" }
springboot4-starter-quartz = { module = "org.springframework.boot:spring-boot-starter-quartz", version.ref = "springboot4" }
Expand Down
1 change: 1 addition & 0 deletions sentry-spring-7/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ dependencies {
testImplementation(libs.springboot4.starter.webflux)
testImplementation(libs.springboot4.starter.restclient)
testImplementation(libs.springboot4.starter.webclient)
testImplementation(libs.springboot4.resttestclient)
testImplementation(projects.sentryReactor)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class SentrySpringSubscriptionHandlerTest {
whenever(parameters.environment).thenReturn(dataFetchingEnvironment)
val resultObject =
SentrySpringSubscriptionHandler()
.onSubscriptionResult(Flux.error<Any?>(exception), scopes, exceptionReporter, parameters)
assertThrows<IllegalStateException> { (resultObject as Flux<Any?>).blockFirst() }
.onSubscriptionResult(Flux.error<Any>(exception), scopes, exceptionReporter, parameters)
assertThrows<IllegalStateException> { (resultObject as Flux<Any>).blockFirst() }

verify(exceptionReporter)
.captureThrowable(
Expand Down Expand Up @@ -77,12 +77,12 @@ class SentrySpringSubscriptionHandlerTest {
val resultObject =
SentrySpringSubscriptionHandler()
.onSubscriptionResult(
Flux.error<Any?>(wrappedException),
Flux.error<Any>(wrappedException),
scopes,
exceptionReporter,
parameters,
)
assertThrows<SubscriptionPublisherException> { (resultObject as Flux<Any?>).blockFirst() }
assertThrows<SubscriptionPublisherException> { (resultObject as Flux<Any>).blockFirst() }

verify(exceptionReporter)
.captureThrowable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import io.sentry.spring7.tracing.SentryTracingConfiguration
import io.sentry.spring7.tracing.SentryTracingFilter
import io.sentry.spring7.tracing.SentryTransaction
import io.sentry.transport.ITransport
import java.time.Duration
import java.util.concurrent.Callable
import java.util.concurrent.TimeUnit
import kotlin.test.BeforeTest
Expand All @@ -42,9 +41,9 @@ import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.resttestclient.TestRestTemplate
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.web.server.test.LocalServerPort
import org.springframework.boot.web.server.test.client.TestRestTemplate
import org.springframework.boot.test.web.server.LocalServerPort
import org.springframework.boot.web.servlet.FilterRegistrationBean
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
Expand Down Expand Up @@ -80,13 +79,15 @@ import org.springframework.web.reactive.function.client.WebClient
class SentrySpringIntegrationTest {

companion object {
@JvmStatic
@BeforeClass
fun `configure awaitlity`() {
fun `configure awaitlity`(): Unit {
Awaitility.setDefaultTimeout(500, TimeUnit.MILLISECONDS)
}

@JvmStatic
@AfterClass
fun `reset awaitility`() {
fun `reset awaitility`(): Unit {
Awaitility.reset()
}
}
Expand Down Expand Up @@ -230,10 +231,8 @@ class SentrySpringIntegrationTest {

restTemplate.getForEntity("http://localhost:$port/throws-handled", String::class.java)

await.during(Duration.ofSeconds(2)).untilAsserted {
verify(transport, never())
.send(checkEvent { event -> assertThat(event).isNotNull() }, anyOrNull())
}
verify(transport, never())
.send(checkEvent { event -> assertThat(event).isNotNull() }, anyOrNull())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Test Timing Issue Causes Inconsistent Results

Race condition in test logic: The original test used await.during(Duration.ofSeconds(2)).untilAsserted to wait and verify that no events were sent for handled exceptions. The change to immediate verification with verify(transport, never()) creates a race condition where the test could incorrectly pass if Sentry events are sent asynchronously after the verification. This is particularly problematic since other tests in the same file still use await.untilAsserted, indicating that asynchronous processing occurs in this system.

Fix in Cursor Fix in Web

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import org.mockito.kotlin.whenever
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.ApplicationRunner
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.security.autoconfigure.reactive.ReactiveSecurityAutoConfiguration
import org.springframework.boot.security.autoconfigure.servlet.SecurityAutoConfiguration
import org.springframework.boot.security.autoconfigure.SecurityAutoConfiguration
import org.springframework.boot.security.autoconfigure.web.reactive.ReactiveWebSecurityAutoConfiguration
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.web.server.test.LocalServerPort
import org.springframework.boot.test.web.server.LocalServerPort
import org.springframework.context.annotation.Bean
import org.springframework.http.ResponseEntity
import org.springframework.test.context.junit4.SpringRunner
Expand Down Expand Up @@ -136,7 +136,7 @@ class SentryWebfluxIntegrationTest {
}

@SpringBootApplication(
exclude = [ReactiveSecurityAutoConfiguration::class, SecurityAutoConfiguration::class]
exclude = [ReactiveWebSecurityAutoConfiguration::class, SecurityAutoConfiguration::class]
)
open class App {
private val transport = mock<ITransport>().also { whenever(it.isHealthy).thenReturn(true) }
Expand Down
1 change: 1 addition & 0 deletions sentry-spring-boot-4/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ dependencies {
testImplementation(libs.springboot4.starter.webflux)
testImplementation(libs.springboot4.starter.restclient)
testImplementation(libs.springboot4.starter.webclient)
testImplementation(libs.springboot4.resttestclient)
}

configure<SourceSetContainer> { test { java.srcDir("src/test/java") } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import org.mockito.kotlin.whenever
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.resttestclient.TestRestTemplate
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.web.server.test.LocalServerPort
import org.springframework.boot.web.server.test.client.TestRestTemplate
import org.springframework.boot.test.web.server.LocalServerPort
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import io.sentry.spring.jakarta.tracing.SentryTracingConfiguration
import io.sentry.spring.jakarta.tracing.SentryTracingFilter
import io.sentry.spring.jakarta.tracing.SentryTransaction
import io.sentry.transport.ITransport
import java.time.Duration
import java.util.concurrent.Callable
import java.util.concurrent.TimeUnit
import kotlin.test.BeforeTest
Expand Down Expand Up @@ -230,10 +229,8 @@ class SentrySpringIntegrationTest {

restTemplate.getForEntity("http://localhost:$port/throws-handled", String::class.java)

await.during(Duration.ofSeconds(2)).untilAsserted {
verify(transport, never())
.send(checkEvent { event -> assertThat(event).isNotNull() }, anyOrNull())
}
verify(transport, never())
.send(checkEvent { event -> assertThat(event).isNotNull() }, anyOrNull())
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import io.sentry.spring.tracing.SentryTracingConfiguration
import io.sentry.spring.tracing.SentryTracingFilter
import io.sentry.spring.tracing.SentryTransaction
import io.sentry.transport.ITransport
import java.time.Duration
import java.util.concurrent.Callable
import java.util.concurrent.TimeUnit
import kotlin.test.BeforeTest
Expand Down Expand Up @@ -231,10 +230,8 @@ class SentrySpringIntegrationTest {

restTemplate.getForEntity("http://localhost:$port/throws-handled", String::class.java)

await.during(Duration.ofSeconds(2)).untilAsserted {
verify(transport, never())
.send(checkEvent { event -> assertThat(event).isNotNull() }, anyOrNull())
}
verify(transport, never())
.send(checkEvent { event -> assertThat(event).isNotNull() }, anyOrNull())
}

@Test
Expand Down
Loading