gateway tests: TestMarshalBodyAllocatesTwoBodies skips under -race, where sync.Pool lets go

0b99b8fbe (#4004) added a bound of 2.5x the body on what marshalBody
allocates. Under -race, sync.Pool drops a quarter of what is put in it,
so json.Marshal's encodeState isn't reused across marshalItems' items
and each one allocates afresh. CI's Race job on macOS went red at
25df3187b ("marshalBody allocated 184 MiB for a 47 MiB body, want at
most 2.5x"), the first Test run after 0b99b8fbe that wasn't cancelled.
The test now skips under raceOn, as parse_memo_test.go's two pool
bounds already do (race_on_test.go).

Run on mote at origin/main df9376592:
- before: go test -race -run TestMarshalBody ./internal/gateway: FAIL,
  176 MiB for 47 MiB.
- after: the same, ok (AllocatesTwoBodies SKIP, IsJSONMarshal PASS);
  without -race: ok, marshalBody 98 MiB for 47 MiB (bound 117), against
  json.Marshal's 205 MiB, so the bound still fails if marshalBody
  falls back to json.Marshal's growth. go vet ./internal/gateway ok,
  gofmt clean.
Not run: the full suite (test file only, one test).
This commit is contained in:
yetone
2026-10-28 18:58:14 +08:00
parent df9376592d
commit d3f3f33811
+3
View File
@@ -53,6 +53,9 @@ func TestMarshalBodyIsJSONMarshal(t *testing.T) {
// and its items: json.Marshal's doubling buffer took it from 45 to 316
// MiB (#4004).
func TestMarshalBodyAllocatesTwoBodies(t *testing.T) {
if raceOn {
t.Skip("under -race sync.Pool drops what json.Marshal's encoders keep, so each item allocates afresh")
}
big := strings.Repeat("tool output line\n", 1<<14)
msgs := make([]any, 0, 170)
for range 170 {