From 4acea46736c6c07b64ed60e0aabbcdf3c8913ddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Untersch=C3=BCtz?= Date: Mon, 23 Nov 2026 19:55:42 +0100 Subject: [PATCH] fix(ci): build and push only after lint and tests pass The build job, and so the image job after it, now needs lint and test: a failing test no longer lets CI go on to push images from main. TestBackgroundRefresh failed on CI now and then with "TempDir RemoveAll cleanup: directory not empty": a refresh started by a visit updates the cache before writing the snapshot to disk, so the test could end and remove the directory mid-write. Visit-triggered refreshes are tracked, and the test harness waits for them before its directory is removed. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3 --- .gitea/workflows/ci.yaml | 3 +++ internal/statuspage/statuspage.go | 7 ++++++- internal/statuspage/statuspage_test.go | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index e7ae183..b345c2a 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -122,6 +122,9 @@ jobs: run: go test -p 1 -count=1 ./... build: + # Nothing is built or pushed from code that fails lint or tests; the + # image job waits for this one. + needs: [lint, test] runs-on: ubuntu-latest outputs: version: ${{ steps.binaries.outputs.version }} diff --git a/internal/statuspage/statuspage.go b/internal/statuspage/statuspage.go index f4d582f..362712f 100644 --- a/internal/statuspage/statuspage.go +++ b/internal/statuspage/statuspage.go @@ -60,6 +60,8 @@ type Server struct { mu sync.Mutex cache map[string]entry refreshing map[string]bool + // background tracks refreshes started by visits. + background sync.WaitGroup } // entry is one cached page, also its on-disk form. @@ -309,7 +311,7 @@ func (s *Server) lookup(ctx context.Context, key, host, slug string) (entry, boo s.mu.Unlock() if cached { if s.now().Sub(e.Fetched) >= freshFor { - go s.refresh(context.WithoutCancel(ctx), key, host, slug) + s.background.Go(func() { s.refresh(context.WithoutCancel(ctx), key, host, slug) }) } return e, true } @@ -356,6 +358,9 @@ func (s *Server) refresh(ctx context.Context, key, host, slug string) { s.fetch(ctx, key, host, slug) } +// Wait returns once the background refreshes started by visits are done. +func (s *Server) Wait() { s.background.Wait() } + // Run keeps every known page fresh until ctx ends, so pages stay current // even without visitors and the cache is warm when the API goes away. func (s *Server) Run(ctx context.Context) { diff --git a/internal/statuspage/statuspage_test.go b/internal/statuspage/statuspage_test.go index 20ce9c2..7667bfe 100644 --- a/internal/statuspage/statuspage_test.go +++ b/internal/statuspage/statuspage_test.go @@ -73,6 +73,9 @@ func newHarness(t *testing.T, src *fakeSource, dir string, now *time.Time) harne t.Fatal(err) } s.now = func() time.Time { return *now } + // Runs before the cleanup of a TempDir created earlier, so no refresh + // writes into a directory being removed. + t.Cleanup(s.Wait) gin.SetMode(gin.TestMode) r := gin.New() s.Mount(r) -- 2.54.1