cmd/utils: Add check on hard limit, skip test if below target

This commit is contained in:
lash 2017-12-15 16:30:16 +01:00
parent c6069a627c
commit 4aad14510a

View file

@ -16,12 +16,23 @@
package utils package utils
import "testing" import (
"fmt"
"syscall"
"testing"
)
// TestFileDescriptorLimits simply tests whether the file descriptor allowance // TestFileDescriptorLimits simply tests whether the file descriptor allowance
// per this process can be retrieved. // per this process can be retrieved.
func TestFileDescriptorLimits(t *testing.T) { func TestFileDescriptorLimits(t *testing.T) {
target := 4096 target := 4096
var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
t.Fatal(err)
}
if int(limit.Max) < target {
t.Skip(fmt.Sprintf("system limit is less than desired test target: %d < %d", limit.Max, target))
}
if limit, err := getFdLimit(); err != nil || limit <= 0 { if limit, err := getFdLimit(); err != nil || limit <= 0 {
t.Fatalf("failed to retrieve file descriptor limit (%d): %v", limit, err) t.Fatalf("failed to retrieve file descriptor limit (%d): %v", limit, err)