mirror of
https://github.com/golang/go
synced 2024-11-13 17:20:22 -07:00
net: fix intermittent TestAddFDReturnsError failure
A fix similar to CL 6859043 was effective in resolving the intermittent failure. Fixes #4423. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6854102
This commit is contained in:
parent
4f74bbd24c
commit
d244dd09f3
@ -13,27 +13,26 @@ import (
|
|||||||
// Issue 3590. netFd.AddFD should return an error
|
// Issue 3590. netFd.AddFD should return an error
|
||||||
// from the underlying pollster rather than panicing.
|
// from the underlying pollster rather than panicing.
|
||||||
func TestAddFDReturnsError(t *testing.T) {
|
func TestAddFDReturnsError(t *testing.T) {
|
||||||
l, err := Listen("tcp", "127.0.0.1:0")
|
ln := newLocalListener(t).(*TCPListener)
|
||||||
if err != nil {
|
defer ln.Close()
|
||||||
t.Fatal(err)
|
connected := make(chan bool)
|
||||||
}
|
|
||||||
defer l.Close()
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
c, err := l.Accept()
|
c, err := ln.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
connected <- true
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
c, err := Dial("tcp", l.Addr().String())
|
c, err := DialTCP("tcp", nil, ln.Addr().(*TCPAddr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
<-connected
|
||||||
|
|
||||||
// replace c's pollServer with a closed version.
|
// replace c's pollServer with a closed version.
|
||||||
ps, err := newPollServer()
|
ps, err := newPollServer()
|
||||||
@ -41,7 +40,7 @@ func TestAddFDReturnsError(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
ps.poll.Close()
|
ps.poll.Close()
|
||||||
c.(*TCPConn).conn.fd.pollServer = ps
|
c.conn.fd.pollServer = ps
|
||||||
|
|
||||||
var b [1]byte
|
var b [1]byte
|
||||||
_, err = c.Read(b[:])
|
_, err = c.Read(b[:])
|
||||||
@ -56,5 +55,5 @@ func TestAddFDReturnsError(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.Error(err)
|
t.Error("unexpected error:", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user