]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: fix incredibly racy TestTransportReading100Continue
authorBrad Fitzpatrick <bradfitz@golang.org>
Sat, 30 Mar 2013 18:18:56 +0000 (11:18 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sat, 30 Mar 2013 18:18:56 +0000 (11:18 -0700)
Whoops. I'm surprised it even worked before. (Need two pipes,
not one.)

Also, remove the whole pipe registration business, since it
wasn't even required in the previous version. (I'd later fixed
it at the end of send100Response, but forgot to delete it)

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/8191044

src/pkg/net/http/transport_test.go

index 3caa3845dedf77f4e47e512b81d16320f75a33d8..75ab5dd7d857fab5e768e45988df996047fbc48c 100644 (file)
@@ -1404,23 +1404,6 @@ func TestTransportSocketLateBinding(t *testing.T) {
 func TestTransportReading100Continue(t *testing.T) {
        defer afterTest(t)
 
-       var writers struct {
-               sync.Mutex
-               list []*io.PipeWriter
-       }
-       registerPipe := func(pw *io.PipeWriter) {
-               writers.Lock()
-               defer writers.Unlock()
-               writers.list = append(writers.list, pw)
-       }
-       defer func() {
-               writers.Lock()
-               defer writers.Unlock()
-               for _, pw := range writers.list {
-                       pw.Close()
-               }
-       }()
-
        const numReqs = 5
        reqBody := func(n int) string { return fmt.Sprintf("request body %d", n) }
        reqID := func(n int) string { return fmt.Sprintf("REQ-ID-%d", n) }
@@ -1463,13 +1446,13 @@ Content-Length: %d
 
        tr := &Transport{
                Dial: func(n, addr string) (net.Conn, error) {
-                       pr, pw := io.Pipe()
-                       registerPipe(pw)
+                       sr, sw := io.Pipe() // server read/write
+                       cr, cw := io.Pipe() // client read/write
                        conn := &rwTestConn{
-                               Reader: pr,
-                               Writer: pw,
+                               Reader: cr,
+                               Writer: sw,
                        }
-                       go send100Response(pw, pr)
+                       go send100Response(cw, sr)
                        return conn, nil
                },
                DisableKeepAlives: false,