aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikio Hara <mikioh.mikioh@gmail.com>2016-05-28 03:06:33 +0900
committerMikio Hara <mikioh.mikioh@gmail.com>2016-05-30 03:30:14 +0000
commitdc5b5239e8020ca0b366ba02f99fe87728fa290c (patch)
tree4a89cf4eaa0d05491c754ece9be6e38311c7c851
parent4e01c132d03ee1f862ae8ba9db465d6047f950f2 (diff)
downloadgo-dc5b5239e8020ca0b366ba02f99fe87728fa290c.tar.gz
go-dc5b5239e8020ca0b366ba02f99fe87728fa290c.zip
net: don't call forceCloseSockets in non-TestMain functions
forceCloseSockets is just designed as a kingston valve for TestMain function and is not suitable to keep track of inflight sockets. Fixes #15525. Change-Id: Id967fe5b8da99bb08b699cc45e07bbc3dfc3ae3d Reviewed-on: https://go-review.googlesource.com/23505 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--src/net/dial_test.go7
-rw-r--r--src/net/main_plan9_test.go1
-rw-r--r--src/net/main_unix_test.go1
-rw-r--r--src/net/main_windows_test.go1
-rw-r--r--src/net/timeout_test.go13
5 files changed, 5 insertions, 18 deletions
diff --git a/src/net/dial_test.go b/src/net/dial_test.go
index 5365677011..9fe507e901 100644
--- a/src/net/dial_test.go
+++ b/src/net/dial_test.go
@@ -87,17 +87,14 @@ func TestDialTimeoutFDLeak(t *testing.T) {
// 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()
- }()
+ defer func() { sw.Set(socktest.FilterClose, nil) }()
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
+ return nil, nil
})
const N = 100
diff --git a/src/net/main_plan9_test.go b/src/net/main_plan9_test.go
index 94501cada9..2bc5be88be 100644
--- a/src/net/main_plan9_test.go
+++ b/src/net/main_plan9_test.go
@@ -8,6 +8,7 @@ func installTestHooks() {}
func uninstallTestHooks() {}
+// forceCloseSockets must be called only from TestMain.
func forceCloseSockets() {}
func enableSocketConnect() {}
diff --git a/src/net/main_unix_test.go b/src/net/main_unix_test.go
index bfb4cd0065..0cc129f34d 100644
--- a/src/net/main_unix_test.go
+++ b/src/net/main_unix_test.go
@@ -45,6 +45,7 @@ func uninstallTestHooks() {
}
}
+// forceCloseSockets must be called only from TestMain.
func forceCloseSockets() {
for s := range sw.Sockets() {
closeFunc(s)
diff --git a/src/net/main_windows_test.go b/src/net/main_windows_test.go
index b879717425..6ea318c2a5 100644
--- a/src/net/main_windows_test.go
+++ b/src/net/main_windows_test.go
@@ -32,6 +32,7 @@ func uninstallTestHooks() {
acceptFunc = origAccept
}
+// forceCloseSockets must be called only from TestMain.
func forceCloseSockets() {
for s := range sw.Sockets() {
closeFunc(s)
diff --git a/src/net/timeout_test.go b/src/net/timeout_test.go
index 7991a579fd..14797eedb7 100644
--- a/src/net/timeout_test.go
+++ b/src/net/timeout_test.go
@@ -41,19 +41,6 @@ func TestDialTimeout(t *testing.T) {
defer func() { testHookDialChannel = origTestHookDialChannel }()
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 {
switch runtime.GOOS {
case "plan9", "windows":