skip checking error also on Mac in TestCheckPortAvailability (#8343)

master
Yao Zongyou 5 years ago committed by kannappanr
parent ac2e0596bd
commit 6a19d7b25a
  1. 1
      cmd/globals.go
  2. 16
      cmd/net.go
  3. 4
      cmd/net_test.go

@ -58,6 +58,7 @@ const (
globalMinioDefaultStorageClass = "STANDARD" globalMinioDefaultStorageClass = "STANDARD"
globalWindowsOSName = "windows" globalWindowsOSName = "windows"
globalNetBSDOSName = "netbsd" globalNetBSDOSName = "netbsd"
globalMacOSName = "darwin"
globalMinioModeFS = "mode-server-fs" globalMinioModeFS = "mode-server-fs"
globalMinioModeXL = "mode-server-xl" globalMinioModeXL = "mode-server-xl"
globalMinioModeDistXL = "mode-server-distributed-xl" globalMinioModeDistXL = "mode-server-distributed-xl"

@ -21,7 +21,6 @@ import (
"fmt" "fmt"
"net" "net"
"net/url" "net/url"
"os"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@ -194,19 +193,6 @@ func isHostIP(ipAddress string) bool {
// Note: The check method tries to listen on given port and closes it. // Note: The check method tries to listen on given port and closes it.
// It is possible to have a disconnected client in this tiny window of time. // It is possible to have a disconnected client in this tiny window of time.
func checkPortAvailability(host, port string) (err error) { func checkPortAvailability(host, port string) (err error) {
// Return true if err is "address already in use" error.
isAddrInUseErr := func(err error) (b bool) {
if opErr, ok := err.(*net.OpError); ok {
if sysErr, ok := opErr.Err.(*os.SyscallError); ok {
if errno, ok := sysErr.Err.(syscall.Errno); ok {
b = (errno == syscall.EADDRINUSE)
}
}
}
return b
}
network := []string{"tcp", "tcp4", "tcp6"} network := []string{"tcp", "tcp4", "tcp6"}
for _, n := range network { for _, n := range network {
l, err := net.Listen(n, net.JoinHostPort(host, port)) l, err := net.Listen(n, net.JoinHostPort(host, port))
@ -216,7 +202,7 @@ func checkPortAvailability(host, port string) (err error) {
if err = l.Close(); err != nil { if err = l.Close(); err != nil {
return err return err
} }
} else if isAddrInUseErr(err) { } else if errors.Is(err, syscall.EADDRINUSE) {
// As we got EADDRINUSE error, the port is in use by other process. // As we got EADDRINUSE error, the port is in use by other process.
// Return the error. // Return the error.
return err return err

@ -216,8 +216,8 @@ func TestCheckPortAvailability(t *testing.T) {
} }
for _, testCase := range testCases { for _, testCase := range testCases {
// On MS Windows, skip checking error case due to https://github.com/golang/go/issues/7598 // On MS Windows and Mac, skip checking error case due to https://github.com/golang/go/issues/7598
if runtime.GOOS == globalWindowsOSName && testCase.expectedErr != nil { if (runtime.GOOS == globalWindowsOSName || runtime.GOOS == globalMacOSName) && testCase.expectedErr != nil {
continue continue
} }

Loading…
Cancel
Save