Skip to content

test: narrow the Spring context for tests that don't need the full application - #2113

Merged
netomi merged 2 commits into
mainfrom
test/narrow-jooq-repository-test-context
Aug 31, 2026
Merged

netomi merged 2 commits into
mainfrom
test/narrow-jooq-repository-test-context

Conversation

@netomi

@netomi netomi commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Why

ExtensionVersionJooqRepositoryTest and ExtensionJooqRepositoryTest test ExtensionVersionJooqRepository/ExtensionJooqRepository — plain @Component classes that talk to the database directly through jOOQ, not Spring Data JPA repositories. A bare @SpringBootTest still boots the entire RegistryApplication for them regardless, pulling in every auto-configuration the app has — most notably all ~30 Spring Data JPA repository interfaces, each one's derived/@Query methods individually parsed and validated against the Hibernate metamodel. That's the dominant cost of a full application context in this project: on the order of a minute, spent entirely between the QueryEnhancerFactories log line and whatever comes next, with nothing logged in between. On top of that: JobRunr's SQL storage provider, the full web/MVC layer, security, actuator — none of which either jOOQ repository needs.

What

Adds JooqOnlyTestConfig, a @SpringBootTest(classes = ...) root that imports only what these tests actually require:

  • DataSourceAutoConfiguration — the DataSource
  • FlywayAutoConfiguration — creates the schema
  • HibernateJpaAutoConfiguration — the EntityManager/transaction management the tests use to set up fixtures
  • TransactionAutoConfiguration — @Transactional rollback-per-test support
  • JooqAutoConfiguration — jOOQ's DSLContext
  • @Import({ExtensionVersionJooqRepository.class, ExtensionJooqRepository.class}) — the two repository beans themselves

Both test classes switch to it. Since it's the identical context configuration, Spring's test context cache shares one instance across both.

Verification

  • Both test classes together (21 tests, including a cold Postgres container start, Flyway migration, and full context bootstrap): 35 seconds, down from well over a minute of context startup alone for either one individually before.
  • Full suite: 1061/1061 passing, total runtime down from ~9-10 minutes to 8m1s.

🤖 Generated with Claude Code

ExtensionVersionJooqRepositoryTest and ExtensionJooqRepositoryTest test
ExtensionVersionJooqRepository/ExtensionJooqRepository - plain
@component classes that talk to the database directly through jOOQ,
not Spring Data JPA repositories. A bare @SpringBootTest still boots
the entire RegistryApplication for them regardless, pulling in every
auto-configuration the app has: all ~30 Spring Data JPA repository
interfaces (each one's derived/@query methods individually parsed and
validated against the Hibernate metamodel - the dominant cost of a
full context in this project, on the order of a minute, logged
between "QueryEnhancerFactories" and the next line with nothing in
between), JobRunr's SQL storage provider, the web/MVC layer, security,
actuator, and more - none of which either jOOQ repository needs.

Added JooqOnlyTestConfig, a @SpringBootTest(classes = ...) root that
imports only what these tests actually require: a DataSource, Flyway
(to create the schema), Hibernate/JPA (for the EntityManager and
transaction management the tests use to set up fixtures), and jOOQ's
DSLContext - plus the two repository beans themselves via @import.
Both test classes now use it and, since it's the same context, share
one cached instance across them.

Measured: both test classes together (21 tests, including a cold
Postgres container start, Flyway migration, and context bootstrap)
now run in 35s, down from over a minute of context startup alone for
either one individually. Full suite: 1061/1061 passing, total runtime
down from ~9-10 minutes to 8m1s.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@netomi
netomi requested a review from cstamas August 31, 2026 10:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR speeds up the server’s jOOQ repository integration tests by replacing full RegistryApplication bootstraps with a narrowly scoped Spring Boot test context that only includes the database, Flyway migrations, JPA/transactions for fixture setup, and jOOQ.

Changes:

  • Added JooqOnlyTestConfig to import a minimal set of auto-configurations and explicitly register the two jOOQ repository beans under test.
  • Updated ExtensionVersionJooqRepositoryTest and ExtensionJooqRepositoryTest to use the shared minimal context and disable the web environment.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
server/src/test/java/org/eclipse/openvsx/repositories/JooqOnlyTestConfig.java New minimal Spring Boot test root configuration for jOOQ repository tests.
server/src/test/java/org/eclipse/openvsx/repositories/ExtensionVersionJooqRepositoryTest.java Switched to JooqOnlyTestConfig and WebEnvironment.NONE.
server/src/test/java/org/eclipse/openvsx/repositories/ExtensionJooqRepositoryTest.java Switched to JooqOnlyTestConfig and WebEnvironment.NONE.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Same rationale as the jOOQ repository tests: a bare @SpringBootTest
boots the entire RegistryApplication regardless of what a test
actually uses, paying for every Spring Data JPA repository (the
dominant cost of a full context here), JobRunr, the web layer, and
more.

- ExtensionScanJobRecoveryServiceTest constructs the service under
  test by hand from plain Mockito mocks and only touches Spring for a
  real DataSource (to exercise the actual Postgres advisory lock
  through real connections) - no JPA or jOOQ involved at all. Narrowed
  to DataSourceAutoConfiguration alone.

- NamespaceRepositoryTest needs exactly one Spring Data JPA repository
  interface, NamespaceRepository. @EnableJpaRepositories normally
  scans every repository interface in its base package - which for
  any repository in this project is the same
  org.eclipse.openvsx.repositories package all ~30 of them live in -
  so restricting basePackageClasses alone would not have helped; an
  explicit includeFilter scopes it to just this one interface.

Measured: both together (10 tests, including a cold Postgres container
start and two separate context bootstraps) run in 42.5s. Full suite:
1061/1061 passing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@netomi netomi changed the title test: give the pure-jOOQ repository tests a narrow Spring context test: narrow the Spring context for tests that don't need the full application Aug 31, 2026
@netomi

netomi commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up: two more tests narrowed the same way

Checked the rest of the @SpringBootTest-based test suite for the same opportunity. Most of it genuinely needs the full application (anything going through RepositoryService, the aggregate facade that injects all ~30 JPA repositories, or a real end-to-end HTTP test) — but two more classes clearly didn't:

  • ExtensionScanJobRecoveryServiceTest: the service under test is constructed by hand from plain Mockito mocks; the only real Spring bean it touches is a DataSource, to exercise the actual Postgres advisory lock through real connections. Narrowed to DataSourceAutoConfiguration alone — no JPA, no jOOQ.
  • NamespaceRepositoryTest: needs exactly one Spring Data JPA repository interface, NamespaceRepository. Worth noting: @EnableJpaRepositories scans every repository interface in its base package, and every repository interface in this project lives in the same org.eclipse.openvsx.repositories package — so just restricting basePackageClasses wouldn't have helped at all. An explicit includeFilters (FilterType.ASSIGNABLE_TYPE on NamespaceRepository.class) is what actually scopes it down to the one interface.

Measured: both together (10 tests, including a cold Postgres container start and two separate context bootstraps) run in 42.5s. Full suite: 1061/1061 passing.


🤖 Generated with Claude Code

@netomi
netomi merged commit 4c4b902 into main Aug 31, 2026
5 checks passed
@netomi
netomi deleted the test/narrow-jooq-repository-test-context branch August 31, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants