Skip to content

test: share one Hydra container across the functional suite#181

Merged
ardetrick merged 4 commits into
mainfrom
test/shared-hydra-container
Jul 5, 2026
Merged

test: share one Hydra container across the functional suite#181
ardetrick merged 4 commits into
mainfrom
test/shared-hydra-container

Conversation

@ardetrick

Copy link
Copy Markdown
Owner

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

ardetrick added 4 commits July 5, 2026 14:38
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.
@ardetrick ardetrick merged commit 72870f0 into main Jul 5, 2026
1 check passed
@ardetrick ardetrick deleted the test/shared-hydra-container branch July 5, 2026 20:18
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.

1 participant