@@ -81,14 +81,51 @@ import org.springframework.web.servlet.HandlerExceptionResolver
8181
8282class SentryAutoConfigurationTest {
8383
84- private val contextRunner =
84+ // Base context runner with performance optimizations
85+ private val baseContextRunner =
8586 WebApplicationContextRunner ()
8687 .withConfiguration(
8788 AutoConfigurations .of(
8889 SentryAutoConfiguration ::class .java,
8990 WebMvcAutoConfiguration ::class .java,
9091 )
9192 )
93+ .withPropertyValues(
94+ // Speed up tests by reducing timeouts and disabling expensive operations
95+ " sentry.shutdownTimeoutMillis=0" ,
96+ " sentry.sessionFlushTimeoutMillis=0" ,
97+ " sentry.flushTimeoutMillis=0" ,
98+ " sentry.readTimeoutMillis=50" ,
99+ " sentry.connectionTimeoutMillis=50" ,
100+ " sentry.send-modules=false" , // Disable expensive module sending
101+ " sentry.attach-stacktrace=false" , // Disable expensive stacktrace collection
102+ " sentry.attach-threads=false" , // Disable expensive thread info
103+ " sentry.enable-backpressure-handling=false" ,
104+ " sentry.enable-spotlight=false" ,
105+ " sentry.debug=false" ,
106+ " sentry.max-breadcrumbs=0" , // Disable breadcrumb collection for performance
107+ )
108+
109+ // Use the optimized base runner by default
110+ private val contextRunner =
111+ baseContextRunner.withUserConfiguration(
112+ NoOpTransportConfiguration ::class .java
113+ ) // Use no-op transport to avoid network calls
114+
115+ // Specialized context runners for different test categories
116+ private val dsnEnabledRunner =
117+ baseContextRunner
118+ .withPropertyValues(" sentry.dsn=http://key@localhost/proj" )
119+ .withUserConfiguration(
120+ NoOpTransportConfiguration ::class .java
121+ ) // Use no-op transport to avoid network calls
122+
123+ private val tracingEnabledRunner =
124+ baseContextRunner
125+ .withPropertyValues(" sentry.dsn=http://key@localhost/proj" , " sentry.traces-sample-rate=1.0" )
126+ .withUserConfiguration(
127+ NoOpTransportConfiguration ::class .java
128+ ) // Use no-op transport to avoid network calls
92129
93130 @Test
94131 fun `scopes is not created when auto-configuration dsn is not set` () {
@@ -97,22 +134,17 @@ class SentryAutoConfigurationTest {
97134
98135 @Test
99136 fun `scopes is created when dsn is provided` () {
100- contextRunner.withPropertyValues(" sentry.dsn=http://key@localhost/proj" ).run {
101- assertThat(it).hasSingleBean(IScopes ::class .java)
102- }
137+ dsnEnabledRunner.run { assertThat(it).hasSingleBean(IScopes ::class .java) }
103138 }
104139
105140 @Test
106141 fun `OptionsConfiguration is created if custom one with name sentryOptionsConfiguration is not provided` () {
107- contextRunner.withPropertyValues(" sentry.dsn=http://key@localhost/proj" ).run {
108- assertThat(it).hasSingleBean(Sentry .OptionsConfiguration ::class .java)
109- }
142+ dsnEnabledRunner.run { assertThat(it).hasSingleBean(Sentry .OptionsConfiguration ::class .java) }
110143 }
111144
112145 @Test
113146 fun `OptionsConfiguration with name sentryOptionsConfiguration is created if another one with different name is provided` () {
114- contextRunner
115- .withPropertyValues(" sentry.dsn=http://key@localhost/proj" )
147+ dsnEnabledRunner
116148 .withUserConfiguration(CustomOptionsConfigurationConfiguration ::class .java)
117149 .run {
118150 assertThat(it).getBeans(Sentry .OptionsConfiguration ::class .java).hasSize(2 )
@@ -305,7 +337,7 @@ class SentryAutoConfigurationTest {
305337
306338 @Test
307339 fun `sets SDK version on sent events` () {
308- contextRunner
340+ baseContextRunner
309341 .withPropertyValues(" sentry.dsn=http://key@localhost/proj" )
310342 .withUserConfiguration(MockTransportConfiguration ::class .java)
311343 .run {
@@ -410,7 +442,7 @@ class SentryAutoConfigurationTest {
410442
411443 @Test
412444 fun `sets release on SentryEvents if Git integration is configured` () {
413- contextRunner
445+ baseContextRunner
414446 .withPropertyValues(" sentry.dsn=http://key@localhost/proj" )
415447 .withUserConfiguration(
416448 MockTransportConfiguration ::class .java,
@@ -429,7 +461,7 @@ class SentryAutoConfigurationTest {
429461
430462 @Test
431463 fun `sets custom release on SentryEvents if release property is set and Git integration is configured` () {
432- contextRunner
464+ baseContextRunner
433465 .withPropertyValues(" sentry.dsn=http://key@localhost/proj" , " sentry.release=my-release" )
434466 .withUserConfiguration(
435467 MockTransportConfiguration ::class .java,
@@ -742,7 +774,7 @@ class SentryAutoConfigurationTest {
742774
743775 @Test
744776 fun `when sentry-apache-http-client-5 is on the classpath, creates apache transport factory` () {
745- contextRunner .withPropertyValues(" sentry.dsn=http://key@localhost/proj" ).run {
777+ baseContextRunner .withPropertyValues(" sentry.dsn=http://key@localhost/proj" ).run {
746778 assertThat(it.getBean(SentryOptions ::class .java).transportFactory)
747779 .isInstanceOf(ApacheHttpClientTransportFactory ::class .java)
748780 }
@@ -761,7 +793,7 @@ class SentryAutoConfigurationTest {
761793
762794 @Test
763795 fun `when sentry-apache-http-client-5 is on the classpath and custom transport factory bean is set, does not create apache transport factory` () {
764- contextRunner
796+ baseContextRunner
765797 .withPropertyValues(" sentry.dsn=http://key@localhost/proj" )
766798 .withUserConfiguration(MockTransportConfiguration ::class .java)
767799 .run {
@@ -1097,6 +1129,15 @@ class SentryAutoConfigurationTest {
10971129 @Bean open fun sentryTransport () = transport
10981130 }
10991131
1132+ @Configuration(proxyBeanMethods = false )
1133+ open class NoOpTransportConfiguration {
1134+
1135+ @Bean
1136+ open fun noOpTransportFactory (): ITransportFactory {
1137+ return NoOpTransportFactory .getInstance()
1138+ }
1139+ }
1140+
11001141 @Configuration(proxyBeanMethods = false )
11011142 open class CustomBeforeSendCallbackConfiguration {
11021143
0 commit comments