Ensure oidc-rs-junit-tenant Port Reservation handles parallel test-runs - #97
Open
LudBjork wants to merge 7 commits into
Open
Ensure oidc-rs-junit-tenant Port Reservation handles parallel test-runs#97LudBjork wants to merge 7 commits into
LudBjork wants to merge 7 commits into
Conversation
Seed the scan with a per-JVM SecureRandom, advance through the range, and skip occupied ports immediately. A port this instance picked itself is now tracked, so when another process steals it the reservation rescans (new rescan() method) instead of failing every subsequent start with "Preconfigured port is not free". Externally pinned ports still fail fast. reserved() also closes any socket a concurrent caller reserved while a thread waited, and start() is a no-op while a reservation is already held.
…ails Rescan for port using SafeRandom from PortReservation, ensuring that parallell JVMs don't collide
… stolen Ensure collision of ports don't happen
…stolen
Regression test for the upstream oidc-lib bug where re-running start()
after the previously scanned port was stolen throws IllegalArgumentException
("Preconfigured port ... is not free") and pins the dead port forever.
The ownPort distinction added when making port reservation robust for
parallel test JVMs makes start() abandon the stolen port and reserve a
fresh one instead; this test fails on upstream and passes on this fork.
|
Checklist:
|
…oads the context The extension reserved the port in its constructor but only started WireMock in beforeAll, which runs after SpringExtension has already loaded the context and resolved the JWKS URLs. If the reserved port was stolen in the bind window, startServer() rescanned to a fresh port, leaving the Spring context wired to the old port while WireMock listened on the new one. Start the WireMock server during extension construction instead, so the final port is published to the MOCKAUTHSERVER_PORT system property before the context loads. This keeps reused contexts wired to the port the server actually listens on, even when the port has to be retried.
…contexts) Add a Spring integration test asserting the published MOCKAUTHSERVER_PORT equals the live WireMock server port and that an authenticated request succeeds, plus a second class with identical configuration so a reused (cached) context is checked for port consistency. Add a DefaultAuthProviders unit test that locks the property->JWKS-URL resolution channel and confirms it tracks the port live.
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.
💡 What does this PR do?
This pull request aims to ensure mock server ports from
WireMockAuthenticationServerdo not collide when running parallelll JVM threads for Spring Boot tests.Rids users of
oidc-rs-junit-tenanthaving to use workarounds such as this in order to use the lib while having parallell tests running.🔧 List of changes
PortReservationTest.java– verifies ports are distinct and don't collide. Test-caserestartReservesNewPortWhenPreviousPortIsStolenis specifically to highlight bug is fixed.TenantAnnotationTokenFactoryPortRaceTest.java— verifies that stolen port doesn't get overriden by new port reservation.SecureRandomnumber generator toPortReservation— ensures non-collision with other threads spinning up a mocked oidc resource server.TenantAnnotationTokenFactoryhas 5 attempts at trying to reserve a port before giving up. Otherwise should reserve port via. the new RNG.📋 Checklist