LEFT | RIGHT |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // End-to-end serving tests | 5 // End-to-end serving tests |
6 | 6 |
7 package http_test | 7 package http_test |
8 | 8 |
9 import ( | 9 import ( |
10 "bufio" | 10 "bufio" |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 // and close the connection. | 786 // and close the connection. |
787 func TestServerUnreadRequestBodyLarge(t *testing.T) { | 787 func TestServerUnreadRequestBodyLarge(t *testing.T) { |
788 conn := new(testConn) | 788 conn := new(testConn) |
789 body := strings.Repeat("x", 1<<20) | 789 body := strings.Repeat("x", 1<<20) |
790 conn.readBuf.Write([]byte(fmt.Sprintf( | 790 conn.readBuf.Write([]byte(fmt.Sprintf( |
791 "POST / HTTP/1.1\r\n"+ | 791 "POST / HTTP/1.1\r\n"+ |
792 "Host: test\r\n"+ | 792 "Host: test\r\n"+ |
793 "Content-Length: %d\r\n"+ | 793 "Content-Length: %d\r\n"+ |
794 "\r\n", len(body)))) | 794 "\r\n", len(body)))) |
795 conn.readBuf.Write([]byte(body)) | 795 conn.readBuf.Write([]byte(body)) |
796 | 796 » conn.closec = make(chan bool, 1) |
797 » done := make(chan bool) | |
798 | 797 |
799 ls := &oneConnListener{conn} | 798 ls := &oneConnListener{conn} |
800 go Serve(ls, HandlerFunc(func(rw ResponseWriter, req *Request) { | 799 go Serve(ls, HandlerFunc(func(rw ResponseWriter, req *Request) { |
801 defer close(done) | |
802 if conn.readBuf.Len() < len(body)/2 { | 800 if conn.readBuf.Len() < len(body)/2 { |
803 t.Errorf("on request, read buffer length is %d; expected
about 1MB", conn.readBuf.Len()) | 801 t.Errorf("on request, read buffer length is %d; expected
about 1MB", conn.readBuf.Len()) |
804 } | 802 } |
805 rw.WriteHeader(200) | 803 rw.WriteHeader(200) |
806 rw.(Flusher).Flush() | 804 rw.(Flusher).Flush() |
807 if conn.readBuf.Len() < len(body)/2 { | 805 if conn.readBuf.Len() < len(body)/2 { |
808 t.Errorf("post-WriteHeader, read buffer length is %d; ex
pected about 1MB", conn.readBuf.Len()) | 806 t.Errorf("post-WriteHeader, read buffer length is %d; ex
pected about 1MB", conn.readBuf.Len()) |
809 } | 807 } |
810 })) | 808 })) |
811 » <-done | 809 » <-conn.closec |
812 | 810 |
813 if res := conn.writeBuf.String(); !strings.Contains(res, "Connection: cl
ose") { | 811 if res := conn.writeBuf.String(); !strings.Contains(res, "Connection: cl
ose") { |
814 t.Errorf("Expected a Connection: close header; got response: %s"
, res) | 812 t.Errorf("Expected a Connection: close header; got response: %s"
, res) |
815 } | 813 } |
816 } | 814 } |
817 | 815 |
818 func TestTimeoutHandler(t *testing.T) { | 816 func TestTimeoutHandler(t *testing.T) { |
819 sendHi := make(chan bool, 1) | 817 sendHi := make(chan bool, 1) |
820 writeErrors := make(chan error, 1) | 818 writeErrors := make(chan error, 1) |
821 sayHi := HandlerFunc(func(w ResponseWriter, r *Request) { | 819 sayHi := HandlerFunc(func(w ResponseWriter, r *Request) { |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1518 cmd := exec.Command(os.Args[0], "-test.run=XXXX", "-test.bench=Benchmark
Server") | 1516 cmd := exec.Command(os.Args[0], "-test.run=XXXX", "-test.bench=Benchmark
Server") |
1519 cmd.Env = append([]string{ | 1517 cmd.Env = append([]string{ |
1520 fmt.Sprintf("TEST_BENCH_CLIENT_N=%d", b.N), | 1518 fmt.Sprintf("TEST_BENCH_CLIENT_N=%d", b.N), |
1521 fmt.Sprintf("TEST_BENCH_SERVER_URL=%s", ts.URL), | 1519 fmt.Sprintf("TEST_BENCH_SERVER_URL=%s", ts.URL), |
1522 }, os.Environ()...) | 1520 }, os.Environ()...) |
1523 out, err := cmd.CombinedOutput() | 1521 out, err := cmd.CombinedOutput() |
1524 if err != nil { | 1522 if err != nil { |
1525 b.Errorf("Test failure: %v, with output: %s", err, out) | 1523 b.Errorf("Test failure: %v, with output: %s", err, out) |
1526 } | 1524 } |
1527 } | 1525 } |
LEFT | RIGHT |