mirror of https://github.com/golang/go.git
io: add test for Pipe constructor allocations
Updates #67633 Change-Id: If3da9317ba36cb8a7868db94b45c402e1793e018 Reviewed-on: https://go-review.googlesource.com/c/go/+/588219 Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Mateusz Poliwczak <mpoliwczak34@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
d0146bd85b
commit
b43d6c57de
|
|
@ -421,3 +421,21 @@ func sortBytesInGroups(b []byte, n int) []byte {
|
||||||
slices.SortFunc(groups, bytes.Compare)
|
slices.SortFunc(groups, bytes.Compare)
|
||||||
return bytes.Join(groups, nil)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue