Commit f279a939 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

http: fix racy test with a simpler version

This was seen breaking the slow arm5 builder:
http://godashboard.appspot.com/log/ec54ee302a70c07093e8f5c47454b3eb48768b77e1d8cc7943d8951f8b6696be

The test was unnecessarily complex and didn't benefit from
using httptest.Server. That just got in the way.

R=rsc
CC=golang-dev
https://golang.org/cl/4439088
parent 623e7de1
......@@ -618,49 +618,29 @@ func TestServerExpect(t *testing.T) {
}
func TestServerConsumesRequestBody(t *testing.T) {
log := make(chan string, 100)
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
log <- "got_request"
w.WriteHeader(StatusOK)
log <- "wrote_header"
}))
defer ts.Close()
conn, err := net.Dial("tcp", ts.Listener.Addr().String())
if err != nil {
t.Fatalf("Dial: %v", err)
}
defer conn.Close()
bufr := bufio.NewReader(conn)
gotres := make(chan bool)
go func() {
line, err := bufr.ReadString('\n')
if err != nil {
t.Fatal(err)
conn := new(testConn)
body := strings.Repeat("x", 1<<20)
conn.readBuf.Write([]byte(fmt.Sprintf(
"POST / HTTP/1.1\r\n"+
"Host: test\r\n"+
"Content-Length: %d\r\n"+
"\r\n",len(body))))
conn.readBuf.Write([]byte(body))
done := make(chan bool)
ls := &oneConnListener{conn}
go Serve(ls, HandlerFunc(func(rw ResponseWriter, req *Request) {
if conn.readBuf.Len() < len(body)/2 {
t.Errorf("on request, read buffer length is %d; expected about 1MB", conn.readBuf.Len())
}
log <- line
gotres <- true
}()
size := 1 << 20
log <- "writing_request"
fmt.Fprintf(conn, "POST / HTTP/1.0\r\nContent-Length: %d\r\n\r\n", size)
time.Sleep(25e6) // give server chance to misbehave & speak out of turn
log <- "slept_after_req_headers"
conn.Write([]byte(strings.Repeat("a", size)))
<-gotres
expected := []string{
"writing_request", "got_request",
"slept_after_req_headers", "wrote_header",
"HTTP/1.0 200 OK\r\n"}
for step, e := range expected {
if g := <-log; e != g {
t.Errorf("on step %d expected %q, got %q", step, e, g)
rw.WriteHeader(200)
if g, e := conn.readBuf.Len(), 0; g != e {
t.Errorf("after WriteHeader, read buffer length is %d; want %d", g, e)
}
}
done <- true
}))
<-done
}
func TestTimeoutHandler(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment