From 386d341e7082e43ced89e72b0cd1d06ee6fdcab1 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 15 Oct 2026 23:07:29 +0800 Subject: [PATCH] =?UTF-8?q?tests:=20onUsage's=20tests=20don't=20wait=20out?= =?UTF-8?q?=20the=20price=20catalog's=20first=20load=20=E2=80=94=20TestOnU?= =?UTF-8?q?sageNeverBlocks=20went=20red=20in=20a=20full=20run=20at=20load?= =?UTF-8?q?=2070=E2=80=93100?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The first row a process prices through the catalog loads it: ≈1.5–2s on an idle machine, measured. TestOnUsageRows' row carries its own cost and never loads it, so TestOnUsageNeverBlocks was the first to, and its until (10s) held the load as well as the queue's three 100ms rows; in a full suite at load 70–100 the rows were never all given (12.31s, "never: the queued rows given"). TestDocsExample, run alone, waited for the same load. serve() now prices one row once before a test's rows go in. Injected: with until cut to 1s, origin/main fails TestOnUsageNeverBlocks and TestDocsExample alone, each "never: the row(s) given"; with this change both pass, 3 of 3. Not reproduced by rerunning: 15 of 15 passed under 28 CPU burners. Ran: gofmt; go vet -tags nogui ./internal/middleware/ for darwin, linux, windows; go test -tags nogui -race -count=5 ./internal/middleware/ ok. Full suite: the batch this goes out with ran go test -tags nogui -timeout 45m ./... with every package ok but internal/middleware (this red); internal/middleware ok after. --- internal/middleware/points_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/middleware/points_test.go b/internal/middleware/points_test.go index 6895cdfa9..60cae2742 100644 --- a/internal/middleware/points_test.go +++ b/internal/middleware/points_test.go @@ -7,6 +7,7 @@ import ( "slices" "sort" "strings" + "sync" "testing" "time" @@ -17,8 +18,14 @@ import ( ) // serve serves a Points observer as the gateway would, until the test ends. +var warmPrices sync.Once + func serve(t *testing.T) *observer { t.Helper() + // The first row a process prices loads the price catalog, ≈2s idle and + // past until's 10s at load 80–100: a test about the queue doesn't wait + // for it (TestOnUsageNeverBlocks went red so in a full run). + warmPrices.Do(func() { usage.NewCoster()(usage.Record{Provider: "p"}) }) o := Points().(*observer) stop := o.Serve() t.Cleanup(stop)