LEFT | RIGHT |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 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 // Tests for transport.go | 5 // Tests for transport.go |
6 | 6 |
7 package http_test | 7 package http_test |
8 | 8 |
9 import ( | 9 import ( |
10 "bufio" | 10 "bufio" |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 defer ts.Close() | 287 defer ts.Close() |
288 | 288 |
289 buf := make([]byte, len(msg)) | 289 buf := make([]byte, len(msg)) |
290 | 290 |
291 for i := 0; i < 3; i++ { | 291 for i := 0; i < 3; i++ { |
292 res, err := http.Get(ts.URL) | 292 res, err := http.Get(ts.URL) |
293 if err != nil { | 293 if err != nil { |
294 t.Errorf("Get: %v", err) | 294 t.Errorf("Get: %v", err) |
295 continue | 295 continue |
296 } | 296 } |
| 297 // We want to close this body eventually (before the |
| 298 // defer afterTest at top runs), but not before the |
| 299 // len(addrSeen) check at the bottom of this test, |
| 300 // since Closing this early in the loop would risk |
| 301 // making connections be re-used for the wrong reason. |
| 302 defer res.Body.Close() |
| 303 |
297 if res.ContentLength != int64(len(msg)) { | 304 if res.ContentLength != int64(len(msg)) { |
298 t.Errorf("res.ContentLength = %d; want %d", res.ContentL
ength, len(msg)) | 305 t.Errorf("res.ContentLength = %d; want %d", res.ContentL
ength, len(msg)) |
299 } | 306 } |
300 defer res.Body.Close() | |
301 n, err := res.Body.Read(buf) | 307 n, err := res.Body.Read(buf) |
302 if n != len(msg) || err != io.EOF { | 308 if n != len(msg) || err != io.EOF { |
303 t.Errorf("Read = %v, %v; want 6, EOF", n, err) | 309 t.Errorf("Read = %v, %v; want 6, EOF", n, err) |
304 } | 310 } |
305 } | 311 } |
306 if len(addrSeen) != 1 { | 312 if len(addrSeen) != 1 { |
307 t.Errorf("server saw %d distinct client addresses; want 1", len(
addrSeen)) | 313 t.Errorf("server saw %d distinct client addresses; want 1", len(
addrSeen)) |
308 } | 314 } |
309 } | 315 } |
310 | 316 |
(...skipping 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1719 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, | 1725 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, |
1720 0x17, 0x00, 0xe8, 0xff, 0x42, 0x12, 0x46, 0x16, | 1726 0x17, 0x00, 0xe8, 0xff, 0x42, 0x12, 0x46, 0x16, |
1721 0x06, 0x00, 0x00, 0x00, 0xff, 0xff, 0x01, 0x08, | 1727 0x06, 0x00, 0x00, 0x00, 0xff, 0xff, 0x01, 0x08, |
1722 0x00, 0xf7, 0xff, 0x3d, 0xb1, 0x20, 0x85, 0xfa, | 1728 0x00, 0xf7, 0xff, 0x3d, 0xb1, 0x20, 0x85, 0xfa, |
1723 0x00, 0x00, 0x00, 0x42, 0x12, 0x46, 0x16, 0x06, | 1729 0x00, 0x00, 0x00, 0x42, 0x12, 0x46, 0x16, 0x06, |
1724 0x00, 0x00, 0x00, 0xff, 0xff, 0x01, 0x08, 0x00, | 1730 0x00, 0x00, 0x00, 0xff, 0xff, 0x01, 0x08, 0x00, |
1725 0xf7, 0xff, 0x3d, 0xb1, 0x20, 0x85, 0xfa, 0x00, | 1731 0xf7, 0xff, 0x3d, 0xb1, 0x20, 0x85, 0xfa, 0x00, |
1726 0x00, 0x00, 0x3d, 0xb1, 0x20, 0x85, 0xfa, 0x00, | 1732 0x00, 0x00, 0x3d, 0xb1, 0x20, 0x85, 0xfa, 0x00, |
1727 0x00, 0x00, | 1733 0x00, 0x00, |
1728 } | 1734 } |
LEFT | RIGHT |