From eec28540d1d035c4f237132799de7422c11561dc Mon Sep 17 00:00:00 2001 From: Jonas Hungershausen Date: Mon, 8 Apr 2024 09:49:52 +0200 Subject: [PATCH 1/2] test: deflake session test --- session/handler_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/session/handler_test.go b/session/handler_test.go index cd0a9ddca6c1..1d5b06e65cbf 100644 --- a/session/handler_test.go +++ b/session/handler_test.go @@ -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")) From 15ca892c0a46a7b452edf05f6241051ab7012269 Mon Sep 17 00:00:00 2001 From: Jonas Hungershausen Date: Mon, 15 Apr 2024 10:54:15 +0200 Subject: [PATCH 2/2] chore; u --- session/handler_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/session/handler_test.go b/session/handler_test.go index 1d5b06e65cbf..906a985e7356 100644 --- a/session/handler_test.go +++ b/session/handler_test.go @@ -193,7 +193,7 @@ func TestSessionWhoAmI(t *testing.T) { 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 + return parsed > int(lifespan-5) && parsed <= int(lifespan) }, "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 {