From 351eb8b9bbb8eeb581e19ab7c90d55c5172b1f61 Mon Sep 17 00:00:00 2001 From: sneak Date: Wed, 11 Nov 2026 14:26:20 +0000 Subject: [PATCH] Set the expiry in TestHandleImageEnc_MaxAge inside each subtest (closes #352) The table set the expiry when it was built. The parallel subtests can wait more than 10 seconds behind other tests on a busy host, so the 60 second case saw a max-age under 50. The table now holds the TTL, and each subtest computes the expiry just before generating its token. Model: opus-5-5 --- .../image_cache_control_internal_test.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/handlers/image_cache_control_internal_test.go b/internal/handlers/image_cache_control_internal_test.go index 97db3af..c056719 100644 --- a/internal/handlers/image_cache_control_internal_test.go +++ b/internal/handlers/image_cache_control_internal_test.go @@ -185,13 +185,13 @@ func TestHandleImageEnc_MaxAge(t *testing.T) { tests := []struct { name string - expires time.Time + ttl time.Duration wantAtLeast int wantAtMost int }{ - {"60 second TTL", time.Now().Add(time.Minute), 50, 60}, - {"two-year TTL", time.Now().Add(2 * 365 * 24 * time.Hour), 31536000, 31536000}, - {"no TTL", time.Time{}, 31536000, 31536000}, + {"60 second TTL", time.Minute, 50, 60}, + {"two-year TTL", 2 * 365 * 24 * time.Hour, 31536000, 31536000}, + {"no TTL", 0, 31536000, 31536000}, } for _, tt := range tests { @@ -200,6 +200,14 @@ func TestHandleImageEnc_MaxAge(t *testing.T) { h, srv := newSignedHostServer(t, slog.New(slog.DiscardHandler)) + // The expiry is set here, not in the table: a parallel subtest + // can wait behind other tests for more than the 10 seconds the + // 60 second case allows. + var expires time.Time + if tt.ttl != 0 { + expires = time.Now().Add(tt.ttl) + } + token, err := h.encGen.Generate(&imagerequest.Request{ Source: imagerequest.Source{ Host: signedHost, @@ -209,7 +217,7 @@ func TestHandleImageEnc_MaxAge(t *testing.T) { Size: imagerequest.Size{Width: 50, Height: 50}, Format: imagerequest.FormatJPEG, }, - }, tt.expires) + }, expires) if err != nil { t.Fatalf("Generate() error = %v", err) } -- 2.54.0