LEFT | RIGHT |
(no file at all) | |
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 1709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1720 Op: "accept", | 1720 Op: "accept", |
1721 Err: syscall.EMFILE, | 1721 Err: syscall.EMFILE, |
1722 }}} | 1722 }}} |
1723 err := Serve(ln, HandlerFunc(HandlerFunc(func(ResponseWriter, *Request)
{}))) | 1723 err := Serve(ln, HandlerFunc(HandlerFunc(func(ResponseWriter, *Request)
{}))) |
1724 if err != io.EOF { | 1724 if err != io.EOF { |
1725 t.Errorf("got error %v, want EOF", err) | 1725 t.Errorf("got error %v, want EOF", err) |
1726 } | 1726 } |
1727 } | 1727 } |
1728 | 1728 |
1729 func BenchmarkClientServer(b *testing.B) { | 1729 func BenchmarkClientServer(b *testing.B) { |
| 1730 b.ReportAllocs() |
1730 b.StopTimer() | 1731 b.StopTimer() |
1731 ts := httptest.NewServer(HandlerFunc(func(rw ResponseWriter, r *Request)
{ | 1732 ts := httptest.NewServer(HandlerFunc(func(rw ResponseWriter, r *Request)
{ |
1732 fmt.Fprintf(rw, "Hello world.\n") | 1733 fmt.Fprintf(rw, "Hello world.\n") |
1733 })) | 1734 })) |
1734 defer ts.Close() | 1735 defer ts.Close() |
1735 b.StartTimer() | 1736 b.StartTimer() |
1736 | 1737 |
1737 for i := 0; i < b.N; i++ { | 1738 for i := 0; i < b.N; i++ { |
1738 res, err := Get(ts.URL) | 1739 res, err := Get(ts.URL) |
1739 if err != nil { | 1740 if err != nil { |
(...skipping 14 matching lines...) Expand all Loading... |
1754 | 1755 |
1755 func BenchmarkClientServerParallel4(b *testing.B) { | 1756 func BenchmarkClientServerParallel4(b *testing.B) { |
1756 benchmarkClientServerParallel(b, 4) | 1757 benchmarkClientServerParallel(b, 4) |
1757 } | 1758 } |
1758 | 1759 |
1759 func BenchmarkClientServerParallel64(b *testing.B) { | 1760 func BenchmarkClientServerParallel64(b *testing.B) { |
1760 benchmarkClientServerParallel(b, 64) | 1761 benchmarkClientServerParallel(b, 64) |
1761 } | 1762 } |
1762 | 1763 |
1763 func benchmarkClientServerParallel(b *testing.B, conc int) { | 1764 func benchmarkClientServerParallel(b *testing.B, conc int) { |
| 1765 b.ReportAllocs() |
1764 b.StopTimer() | 1766 b.StopTimer() |
1765 ts := httptest.NewServer(HandlerFunc(func(rw ResponseWriter, r *Request)
{ | 1767 ts := httptest.NewServer(HandlerFunc(func(rw ResponseWriter, r *Request)
{ |
1766 fmt.Fprintf(rw, "Hello world.\n") | 1768 fmt.Fprintf(rw, "Hello world.\n") |
1767 })) | 1769 })) |
1768 defer ts.Close() | 1770 defer ts.Close() |
1769 b.StartTimer() | 1771 b.StartTimer() |
1770 | 1772 |
1771 numProcs := runtime.GOMAXPROCS(-1) * conc | 1773 numProcs := runtime.GOMAXPROCS(-1) * conc |
1772 var wg sync.WaitGroup | 1774 var wg sync.WaitGroup |
1773 wg.Add(numProcs) | 1775 wg.Add(numProcs) |
(...skipping 24 matching lines...) Expand all Loading... |
1798 | 1800 |
1799 // A benchmark for profiling the server without the HTTP client code. | 1801 // A benchmark for profiling the server without the HTTP client code. |
1800 // The client code runs in a subprocess. | 1802 // The client code runs in a subprocess. |
1801 // | 1803 // |
1802 // For use like: | 1804 // For use like: |
1803 // $ go test -c | 1805 // $ go test -c |
1804 // $ ./http.test -test.run=XX -test.bench=BenchmarkServer -test.benchtime=15s
-test.cpuprofile=http.prof | 1806 // $ ./http.test -test.run=XX -test.bench=BenchmarkServer -test.benchtime=15s
-test.cpuprofile=http.prof |
1805 // $ go tool pprof http.test http.prof | 1807 // $ go tool pprof http.test http.prof |
1806 // (pprof) web | 1808 // (pprof) web |
1807 func BenchmarkServer(b *testing.B) { | 1809 func BenchmarkServer(b *testing.B) { |
| 1810 b.ReportAllocs() |
1808 // Child process mode; | 1811 // Child process mode; |
1809 if url := os.Getenv("TEST_BENCH_SERVER_URL"); url != "" { | 1812 if url := os.Getenv("TEST_BENCH_SERVER_URL"); url != "" { |
1810 n, err := strconv.Atoi(os.Getenv("TEST_BENCH_CLIENT_N")) | 1813 n, err := strconv.Atoi(os.Getenv("TEST_BENCH_CLIENT_N")) |
1811 if err != nil { | 1814 if err != nil { |
1812 panic(err) | 1815 panic(err) |
1813 } | 1816 } |
1814 for i := 0; i < n; i++ { | 1817 for i := 0; i < n; i++ { |
1815 res, err := Get(url) | 1818 res, err := Get(url) |
1816 if err != nil { | 1819 if err != nil { |
1817 log.Panicf("Get: %v", err) | 1820 log.Panicf("Get: %v", err) |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2017 handled++ | 2020 handled++ |
2018 h.ServeHTTP(rw, r) | 2021 h.ServeHTTP(rw, r) |
2019 }) | 2022 }) |
2020 ln := &oneConnListener{conn: conn} | 2023 ln := &oneConnListener{conn: conn} |
2021 go Serve(ln, handler) | 2024 go Serve(ln, handler) |
2022 <-conn.closec | 2025 <-conn.closec |
2023 if b.N != handled { | 2026 if b.N != handled { |
2024 b.Errorf("b.N=%d but handled %d", b.N, handled) | 2027 b.Errorf("b.N=%d but handled %d", b.N, handled) |
2025 } | 2028 } |
2026 } | 2029 } |
LEFT | RIGHT |