Skip to content

Commit

Permalink
io: add test for Pipe constructor allocations
Browse files Browse the repository at this point in the history
Updates golang#67633

Change-Id: If3da9317ba36cb8a7868db94b45c402e1793e018
Reviewed-on: https://go-review.googlesource.com/c/go/+/588219
Auto-Submit: Cuong Manh Le <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
Reviewed-by: Mateusz Poliwczak <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Than McIntosh <[email protected]>
  • Loading branch information
cuonglm authored and gopherbot committed Jul 7, 2024
1 parent d0146bd commit b43d6c5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/io/pipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,21 @@ func sortBytesInGroups(b []byte, n int) []byte {
slices.SortFunc(groups, bytes.Compare)
return bytes.Join(groups, nil)
}

var (
rSink *PipeReader
wSink *PipeWriter
)

func TestPipeAllocations(t *testing.T) {
numAllocs := testing.AllocsPerRun(10, func() {
rSink, wSink = Pipe()
})

// go.dev/cl/473535 claimed Pipe() should only do 2 allocations,
// plus the 2 escaping to heap for simulating real world usages.
expectedAllocs := 4
if int(numAllocs) > expectedAllocs {
t.Fatalf("too many allocations for io.Pipe() call: %f", numAllocs)
}
}

0 comments on commit b43d6c5

Please sign in to comment.