cmd/utils: Cross platform compatible fd limit test

This commit is contained in:
lash 2017-12-18 18:24:15 +01:00
parent 4aad14510a
commit 500b44cbdb
4 changed files with 23 additions and 2 deletions

View file

@ -52,3 +52,11 @@ func getFdLimit() (int, error) {
}
return int(limit.Cur), nil
}
func getFdMaxLimit() (int, error) {
var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
return 0, err
}
return int(limit.Max), nil
}

View file

@ -27,10 +27,11 @@ import (
func TestFileDescriptorLimits(t *testing.T) {
target := 4096
var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
hardlimit, err := getFdMaxLimit()
if err != nil {
t.Fatal(err)
}
if int(limit.Max) < target {
if hardlimit < target {
t.Skip(fmt.Sprintf("system limit is less than desired test target: %d < %d", limit.Max, target))
}

View file

@ -48,3 +48,11 @@ func getFdLimit() (int, error) {
}
return int(limit.Cur), nil
}
func getFdMaxLimit() (int, error) {
var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
return 0, err
}
return int(limit.Max), nil
}

View file

@ -39,3 +39,7 @@ func getFdLimit() (int, error) {
// Please see raiseFdLimit for the reason why we use hard coded 16K as the limit
return 16384, nil
}
func getFdMaxLimit() (int, error) {
return getFdLimit()
}