OAuth refresh: deterministic pool-size-1 connection-ownership regression test

Author: tamassolteszCreated Sep 24, 2026Updated Sep 24, 2026
Labelsagent-wip

Part of PLAN-017. Adds the deterministic reproduction that fails on the unfixed code and passes once core-conn-ownership lands. Full design: agent-plans PLAN-017. Stacks on core-conn-ownership (goes green with it).

New test (src/test/java/io/supertokens/test/oauth/OAuthRefreshConnectionOwnershipTest.java; do NOT extend TestOAuthRefreshRaceCondition — it tolerates Core exceptions as noise and can miss this regression).

Primary — nonRotatingRefresh_holdsExactlyOneConnection (no timing):

  • Storage HikariCP maximumPoolSize = 1, short connectionTimeout (~2s) so a nested borrow fails fast.
  • Precreate everything so no incidental DB work happens: an OAuth client with enableRefreshTokenRotation = false, a refresh-token mapping row, and WARM the signing-key cache first (isolates the revocation borrow).
  • Stub Hydra deterministically via a @TestOnly static volatile hook on OAuthProxyHelper / OAuth.doOAuthProxyFormPOST (same pattern as the createSessionBeforeInsertHook test hook): introspect → active:true, exchange → a token pair, WITHOUT real HTTP and WITHOUT releasing con.
  • Issue ONE non-rotating refresh. On unfixed code it self-deadlocks (Connection is not available); after the fix it passes. Assert a connection-acquisition counter == 1 for the whole refresh.

Second isolation — cold/dynamic signing key (pool=1, cache cleared, useDynamicKey=true) to prove the signing borrow is gone too. Test each borrower separately so an early revocation failure can't mask a later signing failure.

Optional regression — threeDistinctTokens_noStarvation (pool=3, CyclicBarrier aligning three distinct-token refreshes; assert all complete without a pool timeout). Keep as an extra guard, not the primary signal. Prefer sqlite/inmemory for the size-1 structural test (CI-cheap, fully deterministic); run the pool=3 test on postgres.

Acceptance. Test is red on the parent's base (pre-fix) and green with core-conn-ownership; asserts one-connection ownership; no CHANGELOG needed.

Depends-on: #1450 Plan: PLAN-017

Source: supertokens/supertokens-core