]> Cypherpunks repositories - gostls13.git/commitdiff
io: add test for Pipe constructor allocations
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 24 May 2024 16:41:22 +0000 (23:41 +0700)
committerGopher Robot <gobot@golang.org>
Sun, 7 Jul 2024 19:43:22 +0000 (19:43 +0000)
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>
src/io/pipe_test.go

index a8c4e306cc35ec38fa68298ac4b8816db4fe8237..fcf94d52d21bcd4234c3492e6f39910fa2abf582 100644 (file)
@@ -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)
+       }
+}