Skip to content

Test cookie expiry with an injected clock - #2344

Merged
hyperxpro merged 1 commit into
mainfrom
fix/cookie-expiry-test-clock
Sep 21, 2026
Merged

hyperxpro merged 1 commit into
mainfrom
fix/cookie-expiry-test-clock

Conversation

@hyperxpro

Copy link
Copy Markdown
Member

Motivation:

CookieStoreTest stores cookies with Max-Age=1, sleeps 2000 ms and expects them evicted. ThreadSafeCookieStore expires a cookie when (now - createdAt) / 1000 > maxAge, so exactly 2000 ms must elapse on System.currentTimeMillis(). That clock ticks coarsely on Windows, the elapsed time read as just under 2000 ms, and the test failed on windows-latest JDK 11 with expected: <2> but was: <3>.

Modification:

Give ThreadSafeCookieStore a package-private constructor taking a LongSupplier clock; the public no-arg constructor is unchanged. Move the expiry check into ThreadSafeCookieStoreExpiryTest, which advances a fake clock instead of sleeping.

Result:

Cookie expiry is tested without Thread.sleep or the wall clock. No public API change.

@hyperxpro
hyperxpro merged commit ee971a4 into main Sep 21, 2026
17 checks passed
@hyperxpro
hyperxpro deleted the fix/cookie-expiry-test-clock branch September 21, 2026 19:38
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