Skip to content

Commit

Permalink
net: enable TestTCPReadWriteAllocs in short mode
Browse files Browse the repository at this point in the history
The change 2096 removed unwanted allocations and a few noises in test
using AllocsPerRun. Now it's safe to enable this canary test on netpoll
hotpaths.

Change-Id: Icdbee813d81c1410a48ea9960d46447042976905
Reviewed-on: https://go-review.googlesource.com/5713
Reviewed-by: Dmitry Vyukov <[email protected]>
  • Loading branch information
cixtor committed Feb 24, 2015
1 parent 7c7126c commit 3dd029a
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/net/tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,19 @@ func TestTCPConcurrentAccept(t *testing.T) {
}
}

func TestTCPReadWriteMallocs(t *testing.T) {
if testing.Short() {
t.Skip("skipping malloc count in short mode")
func TestTCPReadWriteAllocs(t *testing.T) {
switch runtime.GOOS {
case "nacl", "windows":
// NaCl needs to allocate pseudo file descriptor
// stuff. See syscall/fd_nacl.go.
// Windows uses closures and channels for IO
// completion port-based netpoll. See fd_windows.go.
t.Skipf("not supported on %s", runtime.GOOS)
}

ln, err := Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Listen failed: %v", err)
t.Fatal(err)
}
defer ln.Close()
var server Conn
Expand All @@ -510,25 +516,26 @@ func TestTCPReadWriteMallocs(t *testing.T) {
}()
client, err := Dial("tcp", ln.Addr().String())
if err != nil {
t.Fatalf("Dial failed: %v", err)
t.Fatal(err)
}
defer client.Close()
if err := <-errc; err != nil {
t.Fatalf("Accept failed: %v", err)
t.Fatal(err)
}
defer server.Close()
var buf [128]byte
mallocs := testing.AllocsPerRun(1000, func() {
allocs := testing.AllocsPerRun(1000, func() {
_, err := server.Write(buf[:])
if err != nil {
t.Fatalf("Write failed: %v", err)
t.Fatal(err)
}
_, err = io.ReadFull(client, buf[:])
if err != nil {
t.Fatalf("Read failed: %v", err)
t.Fatal(err)
}
})
if mallocs > 0 {
t.Fatalf("Got %v allocs, want 0", mallocs)
if allocs > 0 {
t.Fatalf("got %v; want 0", allocs)
}
}

Expand Down

0 comments on commit 3dd029a

Please sign in to comment.