Skip to content

Speed up tests #4641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 08-04-add_new_modules_for_spring_7_and_spring_boot_4
Choose a base branch
from
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
14 changes: 8 additions & 6 deletions sentry-jul/src/test/kotlin/io/sentry/jul/SentryHandlerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.sentry.SentryLogLevel
import io.sentry.SentryOptions
import io.sentry.checkEvent
import io.sentry.checkLogs
import io.sentry.test.applyTestOptions
import io.sentry.test.initForTest
import io.sentry.transport.ITransport
import java.time.Instant
Expand Down Expand Up @@ -43,6 +44,7 @@ class SentryHandlerTest {
val options = SentryOptions()
options.dsn = "http://key@localhost/proj"
options.setTransportFactory { _, _ -> transport }
applyTestOptions(options)
contextTags?.forEach { options.addContextTag(it) }
logger = Logger.getLogger("jul.SentryHandlerTest")
handler = SentryHandler(options, configureWithLogManager, true)
Expand Down Expand Up @@ -411,7 +413,7 @@ class SentryHandlerTest {
fixture = Fixture(minimumLevel = Level.FINEST)
fixture.logger.finest("testing trace level")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(
Expand All @@ -427,7 +429,7 @@ class SentryHandlerTest {
fixture = Fixture(minimumLevel = Level.FINE)
fixture.logger.fine("testing trace level")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(checkLogs { event -> assertEquals(SentryLogLevel.DEBUG, event.items.first().level) })
Expand All @@ -438,7 +440,7 @@ class SentryHandlerTest {
fixture = Fixture(minimumLevel = Level.CONFIG)
fixture.logger.config("testing debug level")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(checkLogs { event -> assertEquals(SentryLogLevel.DEBUG, event.items.first().level) })
Expand All @@ -449,7 +451,7 @@ class SentryHandlerTest {
fixture = Fixture(minimumLevel = Level.INFO)
fixture.logger.info("testing info level")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(checkLogs { event -> assertEquals(SentryLogLevel.INFO, event.items.first().level) })
Expand All @@ -460,7 +462,7 @@ class SentryHandlerTest {
fixture = Fixture(minimumLevel = Level.WARNING)
fixture.logger.warning("testing warn level")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(checkLogs { event -> assertEquals(SentryLogLevel.WARN, event.items.first().level) })
Expand All @@ -471,7 +473,7 @@ class SentryHandlerTest {
fixture = Fixture(minimumLevel = Level.SEVERE)
fixture.logger.severe("testing error level")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(checkLogs { event -> assertEquals(SentryLogLevel.ERROR, event.items.first().level) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class SentryAppenderTest {
val logger = fixture.getSut(minimumLevel = Level.TRACE)
logger.trace("testing trace level")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(
Expand All @@ -267,7 +267,7 @@ class SentryAppenderTest {
val logger = fixture.getSut(minimumLevel = Level.DEBUG)
logger.debug("testing debug level")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(checkLogs { event -> assertEquals(SentryLogLevel.DEBUG, event.items.first().level) })
Expand All @@ -278,7 +278,7 @@ class SentryAppenderTest {
val logger = fixture.getSut(minimumLevel = Level.INFO)
logger.info("testing info level")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(checkLogs { event -> assertEquals(SentryLogLevel.INFO, event.items.first().level) })
Expand All @@ -289,7 +289,7 @@ class SentryAppenderTest {
val logger = fixture.getSut(minimumLevel = Level.WARN)
logger.warn("testing warn level")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(checkLogs { event -> assertEquals(SentryLogLevel.WARN, event.items.first().level) })
Expand All @@ -300,7 +300,7 @@ class SentryAppenderTest {
val logger = fixture.getSut(minimumLevel = Level.ERROR)
logger.error("testing error level")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(checkLogs { event -> assertEquals(SentryLogLevel.ERROR, event.items.first().level) })
Expand All @@ -311,7 +311,7 @@ class SentryAppenderTest {
val logger = fixture.getSut(minimumLevel = Level.FATAL)
logger.fatal("testing fatal level")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(checkLogs { event -> assertEquals(SentryLogLevel.FATAL, event.items.first().level) })
Expand Down
2 changes: 2 additions & 0 deletions sentry-log4j2/src/test/resources/sentry.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
release=release from sentry.properties
logs.enabled=true
shutdown-timeout=0
session-flush-timeout=0
Comment on lines +3 to +4
Copy link
Contributor

Choose a reason for hiding this comment

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

should these be set in the properties files for jul and logback tests as well?

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import io.sentry.SentryLogLevel
import io.sentry.SentryOptions
import io.sentry.checkEvent
import io.sentry.checkLogs
import io.sentry.test.applyTestOptions
import io.sentry.test.initForTest
import io.sentry.transport.ITransport
import java.time.Instant
Expand Down Expand Up @@ -68,6 +69,7 @@ class SentryAppenderTest {
options.dsn = dsn
options.isSendDefaultPii = sendDefaultPii
options.logs.isEnabled = enableLogs
applyTestOptions(options)
contextTags?.forEach { options.addContextTag(it) }
appender.setOptions(options)
appender.setMinimumBreadcrumbLevel(minimumBreadcrumbLevel)
Expand Down Expand Up @@ -317,7 +319,7 @@ class SentryAppenderTest {
fixture = Fixture(minimumLevel = Level.TRACE, enableLogs = true)
fixture.logger.trace("testing trace level")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(checkLogs { logs -> assertEquals(SentryLogLevel.TRACE, logs.items.first().level) })
Expand All @@ -328,7 +330,7 @@ class SentryAppenderTest {
fixture = Fixture(minimumLevel = Level.DEBUG, enableLogs = true)
fixture.logger.debug("testing debug level")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(checkLogs { logs -> assertEquals(SentryLogLevel.DEBUG, logs.items.first().level) })
Expand All @@ -339,7 +341,7 @@ class SentryAppenderTest {
fixture = Fixture(minimumLevel = Level.INFO, enableLogs = true)
fixture.logger.info("testing info level")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(checkLogs { logs -> assertEquals(SentryLogLevel.INFO, logs.items.first().level) })
Expand All @@ -350,7 +352,7 @@ class SentryAppenderTest {
fixture = Fixture(minimumLevel = Level.WARN, enableLogs = true)
fixture.logger.warn("testing warn level")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(checkLogs { logs -> assertEquals(SentryLogLevel.WARN, logs.items.first().level) })
Expand All @@ -361,7 +363,7 @@ class SentryAppenderTest {
fixture = Fixture(minimumLevel = Level.ERROR, enableLogs = true)
fixture.logger.error("testing error level")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(checkLogs { logs -> assertEquals(SentryLogLevel.ERROR, logs.items.first().level) })
Expand All @@ -372,7 +374,7 @@ class SentryAppenderTest {
fixture = Fixture(minimumLevel = Level.TRACE, enableLogs = true)
fixture.logger.trace("Testing {} level", "TRACE")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(
Expand All @@ -394,7 +396,7 @@ class SentryAppenderTest {
fixture = Fixture(minimumLevel = Level.TRACE, enableLogs = true, encoder = encoder)
fixture.logger.trace("Testing {} level", "TRACE")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(
Expand All @@ -420,7 +422,7 @@ class SentryAppenderTest {
)
fixture.logger.trace("Testing {} level", "TRACE")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(
Expand All @@ -447,7 +449,7 @@ class SentryAppenderTest {
)
fixture.logger.trace("Testing {} level", "TRACE")

Sentry.flush(1000)
Sentry.flush(10)

verify(fixture.transport)
.send(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,51 @@ import org.springframework.web.servlet.HandlerExceptionResolver

class SentryAutoConfigurationTest {

private val contextRunner =
// Base context runner with performance optimizations
private val baseContextRunner =
WebApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(
SentryAutoConfiguration::class.java,
WebMvcAutoConfiguration::class.java,
)
)
.withPropertyValues(
// Speed up tests by reducing timeouts and disabling expensive operations
"sentry.shutdownTimeoutMillis=0",
"sentry.sessionFlushTimeoutMillis=0",
"sentry.flushTimeoutMillis=0",
"sentry.readTimeoutMillis=50",
"sentry.connectionTimeoutMillis=50",
"sentry.send-modules=false", // Disable expensive module sending
"sentry.attach-stacktrace=false", // Disable expensive stacktrace collection
"sentry.attach-threads=false", // Disable expensive thread info
"sentry.enable-backpressure-handling=false",
"sentry.enable-spotlight=false",
"sentry.debug=false",
"sentry.max-breadcrumbs=0", // Disable breadcrumb collection for performance
)

// Use the optimized base runner by default
private val contextRunner =
baseContextRunner.withUserConfiguration(
NoOpTransportConfiguration::class.java
) // Use no-op transport to avoid network calls

// Specialized context runners for different test categories
private val dsnEnabledRunner =
baseContextRunner
.withPropertyValues("sentry.dsn=http://key@localhost/proj")
.withUserConfiguration(
NoOpTransportConfiguration::class.java
) // Use no-op transport to avoid network calls

private val tracingEnabledRunner =
baseContextRunner
.withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.traces-sample-rate=1.0")
.withUserConfiguration(
NoOpTransportConfiguration::class.java
) // Use no-op transport to avoid network calls

@Test
fun `scopes is not created when auto-configuration dsn is not set`() {
Expand All @@ -97,22 +134,17 @@ class SentryAutoConfigurationTest {

@Test
fun `scopes is created when dsn is provided`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj").run {
assertThat(it).hasSingleBean(IScopes::class.java)
}
dsnEnabledRunner.run { assertThat(it).hasSingleBean(IScopes::class.java) }
}

@Test
fun `OptionsConfiguration is created if custom one with name sentryOptionsConfiguration is not provided`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj").run {
assertThat(it).hasSingleBean(Sentry.OptionsConfiguration::class.java)
}
dsnEnabledRunner.run { assertThat(it).hasSingleBean(Sentry.OptionsConfiguration::class.java) }
}

@Test
fun `OptionsConfiguration with name sentryOptionsConfiguration is created if another one with different name is provided`() {
contextRunner
.withPropertyValues("sentry.dsn=http://key@localhost/proj")
dsnEnabledRunner
.withUserConfiguration(CustomOptionsConfigurationConfiguration::class.java)
.run {
assertThat(it).getBeans(Sentry.OptionsConfiguration::class.java).hasSize(2)
Expand Down Expand Up @@ -305,7 +337,7 @@ class SentryAutoConfigurationTest {

@Test
fun `sets SDK version on sent events`() {
contextRunner
baseContextRunner
.withPropertyValues("sentry.dsn=http://key@localhost/proj")
.withUserConfiguration(MockTransportConfiguration::class.java)
.run {
Expand Down Expand Up @@ -410,7 +442,7 @@ class SentryAutoConfigurationTest {

@Test
fun `sets release on SentryEvents if Git integration is configured`() {
contextRunner
baseContextRunner
.withPropertyValues("sentry.dsn=http://key@localhost/proj")
.withUserConfiguration(
MockTransportConfiguration::class.java,
Expand All @@ -429,7 +461,7 @@ class SentryAutoConfigurationTest {

@Test
fun `sets custom release on SentryEvents if release property is set and Git integration is configured`() {
contextRunner
baseContextRunner
.withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.release=my-release")
.withUserConfiguration(
MockTransportConfiguration::class.java,
Expand Down Expand Up @@ -742,7 +774,7 @@ class SentryAutoConfigurationTest {

@Test
fun `when sentry-apache-http-client-5 is on the classpath, creates apache transport factory`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj").run {
baseContextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj").run {
assertThat(it.getBean(SentryOptions::class.java).transportFactory)
.isInstanceOf(ApacheHttpClientTransportFactory::class.java)
}
Expand All @@ -761,7 +793,7 @@ class SentryAutoConfigurationTest {

@Test
fun `when sentry-apache-http-client-5 is on the classpath and custom transport factory bean is set, does not create apache transport factory`() {
contextRunner
baseContextRunner
.withPropertyValues("sentry.dsn=http://key@localhost/proj")
.withUserConfiguration(MockTransportConfiguration::class.java)
.run {
Expand Down Expand Up @@ -1097,6 +1129,15 @@ class SentryAutoConfigurationTest {
@Bean open fun sentryTransport() = transport
}

@Configuration(proxyBeanMethods = false)
open class NoOpTransportConfiguration {

@Bean
open fun noOpTransportFactory(): ITransportFactory {
return NoOpTransportFactory.getInstance()
}
}

@Configuration(proxyBeanMethods = false)
open class CustomBeforeSendCallbackConfiguration {

Expand Down
Loading