Skip to content

test(auth): add EnsureFreshToken 30-second expiry buffer tests#5

Open
chrisipanaque wants to merge 1 commit into
codag-megalith:mainfrom
chrisipanaque:test/expiry-buffer
Open

test(auth): add EnsureFreshToken 30-second expiry buffer tests#5
chrisipanaque wants to merge 1 commit into
codag-megalith:mainfrom
chrisipanaque:test/expiry-buffer

Conversation

@chrisipanaque

Copy link
Copy Markdown

Summary

Adds test coverage for the 30-second proactive refresh buffer in
EnsureFreshToken (internal/auth/refresh.go:65). The buffer ensures
a token is refreshed before it expires, avoiding a 401+retry penalty on
every request in the ~30s window before actual expiry.

What was verified

Case ExpiresAt Expected behaviour
No expiry 0 Cached token, no HTTP call
Outside buffer now + 45s Cached token, no HTTP call
Inside buffer now + 15s Forces a refresh
Already expired now - 10s Forces a refresh

Guard

If the buffer value in cfg.ExpiresAt - <N> > now is changed, at least
one case flips and fails the test:

  • Bumping to 60 → now+45 falls inside the buffer → case 2 fails
  • Dropping to 10 → now+15 falls outside the buffer → case 3 fails

Verification

go test -v -run TestEnsureFreshToken_30sExpiryBuffer ./internal/auth/
go test ./...

The proactive refresh in EnsureFreshToken has a 30-second safety buffer
that triggers a token refresh before the access token actually expires.
This avoids the latency penalty of a 401+retry cycle when a request
lands just after the server-side expiry.

Cover four behaviours at the buffer boundary: no expiry, outside the
buffer (45s remaining), inside the buffer (15s remaining), and already
expired. Each direction of buffer-value change is caught by at least
one case, protecting against accidental regressions.
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