test: share one Hydra container across the functional suite#181
Merged
Conversation
Starts Hydra once per class (@testinstance(PER_CLASS) makes the injected @LocalServerPort available to a non-static @BeforeAll) and registers a unique OAuth2 client per test via the container's upserting createOrReplaceClient — Hydra keys remembered consent by subject + client, so per-test clients preserve the isolation the remember-me tests rely on. Functional suite drops from ~40-50s to ~7s. The refactor exposed three latent defects that the per-test containers and a global-singleton side channel had been masking, all fixed here: HydraAdminClient captured its base path at construction (now resolved lazily per call, with a dedicated ApiClient instead of the SDK's mutable global default); the test pointed that base path at Hydra's public port — the admin API only ever worked because the deleted SDK helper had re-pointed the global client at the admin port; and the test's public proxy read the same property for a different endpoint (it now has its own explicit public base URI).
Under @testinstance(PER_CLASS) the single test instance lives for the whole class, so Playwright joins Hydra as plain instance state in one documented non-static @BeforeAll (which is what can read the injected @LocalServerPort), and the test proxy's public base URI becomes a field on the autowired bean — set beside properties.setBasePath, the same late-binding pattern — instead of a mutable static.
The idiomatic @Testcontainers/@container static-field pattern constructs containers at class-load time, but this container's configuration needs the injected @LocalServerPort, which only exists after the Spring context boots. Recording the reasoning where the deviation lives so it is not refactored into breakage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One Hydra per class (PER_CLASS lifecycle) with a unique client per test via the upserting createOrReplaceClient — per-test clients preserve isolation because Hydra keys remembered consent by subject + client. Functional suite drops from ~40-50s to ~7s. The refactor exposed and fixes three latent defects previously masked by per-test containers and the SDK's global default ApiClient: construction-time base-path capture in HydraAdminClient (now lazy, dedicated ApiClient), the admin base path actually pointing at the public port (admin calls only worked via the deleted helper's global-client mutation), and the test proxy reading that same property for a different endpoint (now has its own public base URI).
🤖 Generated with Claude Code