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

Side by Side Diff: src/pkg/net/dial_test.go

Issue 5650071: code review 5650071: net: avoid TCP self-connect (Closed)
Patch Set: diff -r 3242e3c73955 https://go.googlecode.com/hg/ Created 12 years, 1 month 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:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/pkg/net/tcpsock_posix.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 package net 5 package net
6 6
7 import ( 7 import (
8 "runtime" 8 "runtime"
9 "testing" 9 "testing"
10 "time" 10 "time"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 if !terr.Timeout() { 78 if !terr.Timeout() {
79 t.Fatalf("got error %q; not a timeout", err) 79 t.Fatalf("got error %q; not a timeout", err)
80 } 80 }
81 // Pass. We saw a timeout error. 81 // Pass. We saw a timeout error.
82 return 82 return
83 } 83 }
84 } 84 }
85 } 85 }
86 } 86 }
87
88 func TestSelfConnect(t *testing.T) {
89 // Test that Dial does not honor self-connects.
90 // See the comment in DialTCP.
91
92 // Find a port that would be used as a local address.
93 l, err := Listen("tcp", "127.0.0.1:0")
94 if err != nil {
95 t.Fatal(err)
96 }
97 c, err := Dial("tcp", l.Addr().String())
98 if err != nil {
99 t.Fatal(err)
100 }
101 addr := c.LocalAddr().String()
102 c.Close()
103 l.Close()
104
105 // Try to connect to that address repeatedly.
106 n := 100000
107 if testing.Short() {
108 n = 1000
109 }
110 for i := 0; i < n; i++ {
111 c, err := Dial("tcp", addr)
112 if err == nil {
113 c.Close()
114 t.Errorf("#%d: Dial %q succeeded", i, addr)
115 }
116 }
117 }
OLDNEW
« no previous file with comments | « no previous file | src/pkg/net/tcpsock_posix.go » ('j') | no next file with comments »

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