From fa4704f06086898dba6b7bbe6ade5fb4853de06f Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 1 Nov 2026 09:13:47 +0800 Subject: [PATCH] gui: a test bounding allocations skips its bound under -race Under -race sync.Pool lets a quarter of what is put in it go, so json's encoders and regexp's matchers are made again: four gui tests bounding what a path allocates went red under -race at fd70def82, and at the base before it. TestProviderInfoReadsTheListOnce measured a row at 88 MB against 13 MB without -race, all in catalog.FamilyOf's regexps. raceOn (as internal/gateway has it) now skips the bound in TestStateWriteGrowsNoBufferItsSize, TestProvidersWriteGrowsNoBufferItsSize, TestJSONRowsNotHeldWhole and TestProviderInfoReadsTheListOnce (after its row checks). Without -race they run as before. Run on mote at this tree: - gofmt, go vet ./internal/gui, GOOS=windows and GOOS=linux go vet -tags nogui: ok. - The four tests without -race: PASS. - go test -race ./internal/gui: only TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners (#3949) red, which are red without -race too. Picked onto 7da5b34aa (sessions, gateway); not run again there. --- internal/gui/provider_info_avail_test.go | 3 +++ internal/gui/providerswrite_test.go | 3 +++ internal/gui/race_off_test.go | 5 +++++ internal/gui/race_on_test.go | 8 ++++++++ internal/gui/statewrite_test.go | 3 +++ internal/gui/stats_answer_test.go | 3 +++ 6 files changed, 25 insertions(+) create mode 100644 internal/gui/race_off_test.go create mode 100644 internal/gui/race_on_test.go diff --git a/internal/gui/provider_info_avail_test.go b/internal/gui/provider_info_avail_test.go index 38a3e577d..89895700b 100644 --- a/internal/gui/provider_info_avail_test.go +++ b/internal/gui/provider_info_avail_test.go @@ -54,6 +54,9 @@ func TestProviderInfoReadsTheListOnce(t *testing.T) { t.Fatalf("exposed %d of %d, first %+v", got.Exposed, len(p.Exposed()), got.Models[0]) } + if raceOn { + t.Skip("-race: sync.Pool drops what it holds, so allocations are not what a build allocates") + } bytesPer := func(f func()) uint64 { f() var a, b runtime.MemStats diff --git a/internal/gui/providerswrite_test.go b/internal/gui/providerswrite_test.go index 4e556f2c5..a102ba3a0 100644 --- a/internal/gui/providerswrite_test.go +++ b/internal/gui/providerswrite_test.go @@ -51,6 +51,9 @@ func TestProvidersWrittenAsEncoded(t *testing.T) { // buffer to its size: 27 MB of what forty polls allocated. Each provider // is encoded alone now. func TestProvidersWriteGrowsNoBufferItsSize(t *testing.T) { + if raceOn { + t.Skip("-race: sync.Pool drops what it holds, so allocations are not what a build allocates") + } s := bigProviders() w := &sinkWriter{} writeProvidersJSON(w, s) // json's encoders, warmed diff --git a/internal/gui/race_off_test.go b/internal/gui/race_off_test.go new file mode 100644 index 000000000..1d46792ca --- /dev/null +++ b/internal/gui/race_off_test.go @@ -0,0 +1,5 @@ +//go:build !race + +package gui + +const raceOn = false diff --git a/internal/gui/race_on_test.go b/internal/gui/race_on_test.go new file mode 100644 index 000000000..7749b542f --- /dev/null +++ b/internal/gui/race_on_test.go @@ -0,0 +1,8 @@ +//go:build race + +package gui + +// raceOn says the tests run under -race, where sync.Pool lets a quarter of +// what is put in it go (json's encoders, regexp's matchers), so a test of +// how much a path allocates skips its bound. +const raceOn = true diff --git a/internal/gui/statewrite_test.go b/internal/gui/statewrite_test.go index b1fdc1c12..374d39fa4 100644 --- a/internal/gui/statewrite_test.go +++ b/internal/gui/statewrite_test.go @@ -88,6 +88,9 @@ func TestStateWrittenAsEncoded(t *testing.T) { // and for keepState's sum, growing a buffer to its size each time: 68 MB // of what twenty polls allocated. Each agent is encoded once now, alone. func TestStateWriteGrowsNoBufferItsSize(t *testing.T) { + if raceOn { + t.Skip("-race: sync.Pool drops what it holds, so allocations are not what a build allocates") + } s := bigState() w := &sinkWriter{} writeStateJSON(w, s) // json's encoders, warmed diff --git a/internal/gui/stats_answer_test.go b/internal/gui/stats_answer_test.go index 96b532755..a042d8fec 100644 --- a/internal/gui/stats_answer_test.go +++ b/internal/gui/stats_answer_test.go @@ -87,6 +87,9 @@ func TestSameAnswerNotHeldWhole(t *testing.T) { // writeJSONRows holds no answer-sized buffer: the list goes out a row at a // time, and the whole answer was 25 MB of a warm start's live heap (#2278). func TestJSONRowsNotHeldWhole(t *testing.T) { + if raceOn { + t.Skip("-race: sync.Pool drops what it holds, so allocations are not what a build allocates") + } big := string(bytes.Repeat([]byte("x"), 64<<10)) rows := make([]rowsBufRow, 64) for i := range rows {