tests: onUsage's tests don't wait out the price catalog's first load — TestOnUsageNeverBlocks went red in a full run at load 70–100
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.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user