Skip to content

Commit bc471a5

Browse files
mvdanianlancetaylor
authored andcommitted
net: reduce TestSplice/big's memory usage
The old code used splice on a 2GB []byte when not in short mode, meaning that running 'go test net' when one had 4GB or less free memory would easily result in "out of memory" runtime panics. Instead, use a much smaller size that is still big enough to not fit into a single splice(2) syscall. The new size is just 5MB, so the test uses a fraction of the memory it used to, and there's no longer a need for a different size on short mode. This also speeds up the test, which goes from ~1.23s to ~0.01s on my laptop. Fixes #26867. Change-Id: Iae1daa5c0995b549f41992f44339be32ca1ee5e4 Reviewed-on: https://go-review.googlesource.com/128535 Run-TryBot: Daniel Martí <[email protected]> Reviewed-by: Andrei Tudor Călin <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 15c106d commit bc471a5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/net/splice_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ func testSpliceMultipleWrite(t *testing.T) {
8080
}
8181

8282
func testSpliceBig(t *testing.T) {
83-
size := 1<<31 - 1
84-
if testing.Short() {
85-
size = 1 << 25
86-
}
83+
// The maximum amount of data that internal/poll.Splice will use in a
84+
// splice(2) call is 4 << 20. Use a bigger size here so that we test an
85+
// amount that doesn't fit in a single call.
86+
size := 5 << 20
8787
srv, err := newSpliceTestServer()
8888
if err != nil {
8989
t.Fatal(err)

0 commit comments

Comments
 (0)