Fix TestGracefulStop flakiness (#1767)

This commit is contained in:
dfawley
2017-12-22 12:39:56 -08:00
committed by GitHub
parent 2720857d97
commit 035eb475a7

View File

@ -38,6 +38,7 @@ type delayListener struct {
acceptCalled chan struct{} acceptCalled chan struct{}
allowCloseCh chan struct{} allowCloseCh chan struct{}
cc *delayConn cc *delayConn
dialed bool
} }
func (d *delayListener) Accept() (net.Conn, error) { func (d *delayListener) Accept() (net.Conn, error) {
@ -70,6 +71,13 @@ func (d *delayListener) allowClientRead() {
} }
func (d *delayListener) Dial(to time.Duration) (net.Conn, error) { func (d *delayListener) Dial(to time.Duration) (net.Conn, error) {
if d.dialed {
// Only hand out one connection (net.Dial can return more even after the
// listener is closed). This is not thread-safe, but Dial should never be
// called concurrently in this environment.
return nil, fmt.Errorf("no more conns")
}
d.dialed = true
c, err := net.DialTimeout("tcp", d.Listener.Addr().String(), to) c, err := net.DialTimeout("tcp", d.Listener.Addr().String(), to)
if err != nil { if err != nil {
return nil, err return nil, err