mirror of
https://github.com/golang/go
synced 2024-11-23 16:00:06 -07:00
net: deflake TestDialTimeout{,FDLeak} in the case of TCP simultaneous open
Fixes #11872. Change-Id: Ibc7d8438374c9d90fd4cbefb61426c7f4f96af0d Reviewed-on: https://go-review.googlesource.com/12691 Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
54a966e383
commit
68557de116
@ -124,7 +124,24 @@ func TestDialTimeoutFDLeak(t *testing.T) {
|
|||||||
defer sw.Set(socktest.FilterConnect, nil)
|
defer sw.Set(socktest.FilterConnect, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
before := sw.Sockets()
|
// Avoid tracking open-close jitterbugs between netFD and
|
||||||
|
// socket that leads to confusion of information inside
|
||||||
|
// socktest.Switch.
|
||||||
|
// It may happen when the Dial call bumps against TCP
|
||||||
|
// simultaneous open. See selfConnect in tcpsock_posix.go.
|
||||||
|
defer func() {
|
||||||
|
sw.Set(socktest.FilterClose, nil)
|
||||||
|
forceCloseSockets()
|
||||||
|
}()
|
||||||
|
var mu sync.Mutex
|
||||||
|
var attempts int
|
||||||
|
sw.Set(socktest.FilterClose, func(so *socktest.Status) (socktest.AfterFilter, error) {
|
||||||
|
mu.Lock()
|
||||||
|
attempts++
|
||||||
|
mu.Unlock()
|
||||||
|
return nil, errTimedout
|
||||||
|
})
|
||||||
|
|
||||||
const N = 100
|
const N = 100
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(N)
|
wg.Add(N)
|
||||||
@ -142,9 +159,8 @@ func TestDialTimeoutFDLeak(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
after := sw.Sockets()
|
if attempts < N {
|
||||||
if len(after) != len(before) {
|
t.Errorf("got %d; want >= %d", attempts, N)
|
||||||
t.Errorf("got %d; want %d", len(after), len(before))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,19 @@ func TestDialTimeout(t *testing.T) {
|
|||||||
defer func() { testHookDialChannel = origTestHookDialChannel }()
|
defer func() { testHookDialChannel = origTestHookDialChannel }()
|
||||||
defer sw.Set(socktest.FilterConnect, nil)
|
defer sw.Set(socktest.FilterConnect, nil)
|
||||||
|
|
||||||
|
// Avoid tracking open-close jitterbugs between netFD and
|
||||||
|
// socket that leads to confusion of information inside
|
||||||
|
// socktest.Switch.
|
||||||
|
// It may happen when the Dial call bumps against TCP
|
||||||
|
// simultaneous open. See selfConnect in tcpsock_posix.go.
|
||||||
|
defer func() {
|
||||||
|
sw.Set(socktest.FilterClose, nil)
|
||||||
|
forceCloseSockets()
|
||||||
|
}()
|
||||||
|
sw.Set(socktest.FilterClose, func(so *socktest.Status) (socktest.AfterFilter, error) {
|
||||||
|
return nil, errTimedout
|
||||||
|
})
|
||||||
|
|
||||||
for i, tt := range dialTimeoutTests {
|
for i, tt := range dialTimeoutTests {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "plan9", "windows":
|
case "plan9", "windows":
|
||||||
|
Loading…
Reference in New Issue
Block a user