Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5)

Delta Between Two Patch Sets: src/pkg/net/http/serve_test.go

Issue 12632043: code review 12632043: net/http: fix early side effects in the ResponseWriter'... (Closed)
Left Patch Set: diff -r c71f9b21cc13 https://go.googlecode.com/hg/ Created 11 years, 7 months ago
Right Patch Set: diff -r c6b37ee14a9f https://go.googlecode.com/hg/ Created 11 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/net/http/server.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(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 1797 matching lines...) Expand 10 before | Expand all | Expand 10 after
1808 conn.Close() 1808 conn.Close()
1809 resp.Body.Close() 1809 resp.Body.Close()
1810 1810
1811 got := resp.Header["Connection"] 1811 got := resp.Header["Connection"]
1812 if !reflect.DeepEqual(got, tt.expect) { 1812 if !reflect.DeepEqual(got, tt.expect) {
1813 t.Errorf("wrong Connection headers for request %q. Got % q expect %q", got, tt.expect) 1813 t.Errorf("wrong Connection headers for request %q. Got % q expect %q", got, tt.expect)
1814 } 1814 }
1815 } 1815 }
1816 } 1816 }
1817 1817
1818 // See golang.org/issue/5660
1819 func TestServerReaderFromOrder(t *testing.T) {
1820 defer afterTest(t)
1821 pr, pw := io.Pipe()
1822 const size = 3 << 20
1823 ts := httptest.NewServer(HandlerFunc(func(rw ResponseWriter, req *Reques t) {
1824 rw.Header().Set("Content-Type", "text/plain") // prevent sniffin g path
1825 done := make(chan bool)
1826 go func() {
1827 io.Copy(rw, pr)
1828 close(done)
1829 }()
1830 time.Sleep(25 * time.Millisecond) // give Copy a chance to break things
1831 n, err := io.Copy(ioutil.Discard, req.Body)
1832 if err != nil {
1833 t.Errorf("handler Copy: %v", err)
1834 return
1835 }
1836 if n != size {
1837 t.Errorf("handler Copy = %d; want %d", n, size)
1838 }
1839 pw.Write([]byte("hi"))
1840 pw.Close()
1841 <-done
1842 }))
1843 defer ts.Close()
1844
1845 req, err := NewRequest("POST", ts.URL, io.LimitReader(neverEnding('a'), size))
1846 if err != nil {
1847 t.Fatal(err)
1848 }
1849 res, err := DefaultClient.Do(req)
1850 if err != nil {
1851 t.Fatal(err)
1852 }
1853 all, err := ioutil.ReadAll(res.Body)
1854 if err != nil {
1855 t.Fatal(err)
1856 }
1857 res.Body.Close()
1858 if string(all) != "hi" {
1859 t.Errorf("Body = %q; want hi", all)
1860 }
1861 }
1862
1818 func BenchmarkClientServer(b *testing.B) { 1863 func BenchmarkClientServer(b *testing.B) {
1819 b.ReportAllocs() 1864 b.ReportAllocs()
1820 b.StopTimer() 1865 b.StopTimer()
1821 ts := httptest.NewServer(HandlerFunc(func(rw ResponseWriter, r *Request) { 1866 ts := httptest.NewServer(HandlerFunc(func(rw ResponseWriter, r *Request) {
1822 fmt.Fprintf(rw, "Hello world.\n") 1867 fmt.Fprintf(rw, "Hello world.\n")
1823 })) 1868 }))
1824 defer ts.Close() 1869 defer ts.Close()
1825 b.StartTimer() 1870 b.StartTimer()
1826 1871
1827 for i := 0; i < b.N; i++ { 1872 for i := 0; i < b.N; i++ {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 handled++ 2150 handled++
2106 h.ServeHTTP(rw, r) 2151 h.ServeHTTP(rw, r)
2107 }) 2152 })
2108 ln := &oneConnListener{conn: conn} 2153 ln := &oneConnListener{conn: conn}
2109 go Serve(ln, handler) 2154 go Serve(ln, handler)
2110 <-conn.closec 2155 <-conn.closec
2111 if b.N != handled { 2156 if b.N != handled {
2112 b.Errorf("b.N=%d but handled %d", b.N, handled) 2157 b.Errorf("b.N=%d but handled %d", b.N, handled)
2113 } 2158 }
2114 } 2159 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b