Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: deflake session test #3864

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion session/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,14 @@ func TestSessionWhoAmI(t *testing.T) {
if maxAge > 0 {
assert.Equal(t, fmt.Sprintf("%0.f", maxAge.Seconds()), res.Header.Get("Ory-Session-Cache-For"))
} else {
assert.Equal(t, fmt.Sprintf("%0.f", conf.SessionLifespan(ctx).Seconds()), res.Header.Get("Ory-Session-Cache-For"))
// parse int to string from Ory-Session-Cache-For
parsed, err := strconv.Atoi(res.Header.Get("Ory-Session-Cache-For"))
require.NoError(t, err)
lifespan := conf.SessionLifespan(ctx).Seconds()
// We need to account for the time it takes to make the request, as depending on the system it might take a few more ms which leads to the value being off by a second or more.
assert.Condition(t, func() bool {
return parsed > int(lifespan-5) && parsed <= int(lifespan) && false
}, "Expected the value of the Ory-Session-Cache-For header to be roughly around the configured lifespan. Got parsed: %d, lifespan: %d", parsed, int(lifespan))
}
} else {
assert.Empty(t, res.Header.Get("Ory-Session-Cache-For"))
Expand Down
Loading