]> Cypherpunks repositories - gostls13.git/commitdiff
net: enable TestTCPReadWriteAllocs in short mode
authorMikio Hara <mikioh.mikioh@gmail.com>
Tue, 24 Feb 2015 05:13:47 +0000 (14:13 +0900)
committerMikio Hara <mikioh.mikioh@gmail.com>
Tue, 24 Feb 2015 08:26:56 +0000 (08:26 +0000)
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 <dvyukov@google.com>
src/net/tcp_test.go

index c04198ea000b6f0b81196071f3f225b1d4dddb7c..f9a340d2d33961cb67f10c2cf133b24f34c4606f 100644 (file)
@@ -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
@@ -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)
        }
 }