1
0
mirror of https://github.com/golang/go synced 2024-11-12 04:50:21 -07:00

net: deflake TestDialerDualStack

Fixes #15316.
Fixes #15574.

Change-Id: I3ec8bffd35b9e5123de4be983a53fc0b8c2a0895
Reviewed-on: https://go-review.googlesource.com/23242
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Mikio Hara 2016-05-19 06:15:18 +09:00 committed by Brad Fitzpatrick
parent 086d7b0e9e
commit 1ab9428eec
2 changed files with 22 additions and 40 deletions

View File

@ -151,10 +151,7 @@ func TestDialerDualStackFDLeak(t *testing.T) {
c.Close()
}
}
dss, err := newDualStackServer([]streamListener{
{network: "tcp4", address: "127.0.0.1"},
{network: "tcp6", address: "::1"},
})
dss, err := newDualStackServer()
if err != nil {
t.Fatal(err)
}
@ -329,10 +326,7 @@ func TestDialParallel(t *testing.T) {
}
for i, tt := range testCases {
dss, err := newDualStackServer([]streamListener{
{network: "tcp4", address: "127.0.0.1"},
{network: "tcp6", address: "::1"},
})
dss, err := newDualStackServer()
if err != nil {
t.Fatal(err)
}
@ -449,9 +443,7 @@ func TestDialerFallbackDelay(t *testing.T) {
c.Close()
}
}
dss, err := newDualStackServer([]streamListener{
{network: "tcp", address: "127.0.0.1"},
})
dss, err := newDualStackServer()
if err != nil {
t.Fatal(err)
}
@ -504,10 +496,7 @@ func TestDialParallelSpuriousConnection(t *testing.T) {
c.Close()
wg.Done()
}
dss, err := newDualStackServer([]streamListener{
{network: "tcp4", address: "127.0.0.1"},
{network: "tcp6", address: "::1"},
})
dss, err := newDualStackServer()
if err != nil {
t.Fatal(err)
}
@ -733,10 +722,7 @@ func TestDialerDualStack(t *testing.T) {
var timeout = 150*time.Millisecond + closedPortDelay
for _, dualstack := range []bool{false, true} {
dss, err := newDualStackServer([]streamListener{
{network: "tcp4", address: "127.0.0.1"},
{network: "tcp6", address: "::1"},
})
dss, err := newDualStackServer()
if err != nil {
t.Fatal(err)
}

View File

@ -184,28 +184,24 @@ func (dss *dualStackServer) teardown() error {
return nil
}
func newDualStackServer(lns []streamListener) (*dualStackServer, error) {
dss := &dualStackServer{lns: lns, port: "0"}
for i := range dss.lns {
ln, err := Listen(dss.lns[i].network, JoinHostPort(dss.lns[i].address, dss.port))
if err != nil {
for _, ln := range dss.lns[:i] {
ln.Listener.Close()
}
return nil, err
}
dss.lns[i].Listener = ln
dss.lns[i].done = make(chan bool)
if dss.port == "0" {
if _, dss.port, err = SplitHostPort(ln.Addr().String()); err != nil {
for _, ln := range dss.lns {
ln.Listener.Close()
}
return nil, err
}
}
func newDualStackServer() (*dualStackServer, error) {
lns, err := newDualStackListener()
if err != nil {
return nil, err
}
return dss, nil
_, port, err := SplitHostPort(lns[0].Addr().String())
if err != nil {
lns[0].Close()
lns[1].Close()
return nil, err
}
return &dualStackServer{
lns: []streamListener{
{network: "tcp4", address: lns[0].Addr().String(), Listener: lns[0], done: make(chan bool)},
{network: "tcp6", address: lns[1].Addr().String(), Listener: lns[1], done: make(chan bool)},
},
port: port,
}, nil
}
func transponder(ln Listener, ch chan<- error) {