From 34a80529cd55a1e68dd6fe89806fec1473af7d4c Mon Sep 17 00:00:00 2001 From: Tom Proctor Date: Mon, 9 Nov 2026 16:56:01 +0000 Subject: [PATCH] gocache/awscache: fix flaky TestDiskSpool The GET handler closes its spool in a deferred call after io.Copy returns. The client has the full body when it gets Content-Length bytes, so wantHit can return before the spool is closed. Close the test server before the test checks the spool dir to make sure all outstanding requests are drained first. Updates #cleanup --- gocache/awscache/awscache_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gocache/awscache/awscache_test.go b/gocache/awscache/awscache_test.go index ca41306..30e46c1 100644 --- a/gocache/awscache/awscache_test.go +++ b/gocache/awscache/awscache_test.go @@ -211,6 +211,7 @@ func (env *testEnv) newCache(modify func(*Config)) *Cache { type client struct { t *testing.T h *Handler + ts *httptest.Server hc *cachers.HTTPClient } @@ -219,8 +220,9 @@ func (env *testEnv) newClient(c *Cache, g Grant) *client { ts := httptest.NewServer(h) env.t.Cleanup(ts.Close) return &client{ - t: env.t, - h: h, + t: env.t, + h: h, + ts: ts, hc: &cachers.HTTPClient{ BaseURL: ts.URL, Disk: &cachers.DiskCache{Dir: env.t.TempDir()}, @@ -473,6 +475,8 @@ func TestDiskSpool(t *testing.T) { data := randBytes(1 << 20) cl.put("abab01", "0a01", data) cl.wantHit("abab01", "0a01", data) + cl.ts.Close() + ents, err := os.ReadDir(c.cfg.SpoolDir) if err != nil { t.Fatal(err)