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 at25df3187b("marshalBody allocated 184 MiB for a 47 MiB body, want at most 2.5x"), the first Test run after0b99b8fbethat 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/maindf9376592: - 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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user