Skip to content

Commit

Permalink
test(auth): use the same now when checking tokenstate (#10952)
Browse files Browse the repository at this point in the history
I am not sure if this will fix the test, but it is a better
behaviour either way I think. If this happens again my only guess
is it has to do with rounding depending on the initial time
captured. If this test fails again we should use a reletive offset
time instead of a fully random time.

Releated: #10950
  • Loading branch information
codyoss authored Oct 4, 2024
1 parent e7c85ac commit 3377a3c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,14 @@ func (c *cachedTokenProvider) tokenState() tokenState {
c.mu.Lock()
defer c.mu.Unlock()
t := c.cachedToken
now := timeNow()
if t == nil || t.Value == "" {
return invalid
} else if t.Expiry.IsZero() {
return fresh
} else if timeNow().After(t.Expiry.Round(0)) {
} else if now.After(t.Expiry.Round(0)) {
return invalid
} else if timeNow().After(t.Expiry.Round(0).Add(-c.expireEarly)) {
} else if now.After(t.Expiry.Round(0).Add(-c.expireEarly)) {
return stale
}
return fresh
Expand Down

0 comments on commit 3377a3c

Please sign in to comment.