mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
syscall: use RLIMIT_CPU instead of RLIMIT_NOFILE
The latter is subject to kern.maxfilelimit restrictions on darwin which are not reflected in the return value. This makes it difficult to reliably restore the default after the test is complete. RLIMIT_CPU should hopefully sidestep this problem. Updates #40564. Change-Id: Ifb33c7d46f2708130cef366dc245c643a2d5e465 Reviewed-on: https://go-review.googlesource.com/c/go/+/383234 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Trust: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
2e2ef31778
commit
ea3c546e9e
1 changed files with 4 additions and 17 deletions
|
|
@ -328,8 +328,7 @@ func TestUnixRightsRoundtrip(t *testing.T) {
|
|||
|
||||
func TestRlimit(t *testing.T) {
|
||||
var rlimit, zero syscall.Rlimit
|
||||
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit)
|
||||
if err != nil {
|
||||
if err := syscall.Getrlimit(syscall.RLIMIT_CPU, &rlimit); err != nil {
|
||||
t.Fatalf("Getrlimit: save failed: %v", err)
|
||||
}
|
||||
if zero == rlimit {
|
||||
|
|
@ -337,31 +336,19 @@ func TestRlimit(t *testing.T) {
|
|||
}
|
||||
set := rlimit
|
||||
set.Cur = set.Max - 1
|
||||
if (runtime.GOOS == "darwin" || runtime.GOOS == "ios") && set.Cur > 4096 {
|
||||
// rlim_min for RLIMIT_NOFILE should be equal to
|
||||
// or lower than kern.maxfilesperproc, which on
|
||||
// some machines are 4096. See #40564.
|
||||
set.Cur = 4096
|
||||
}
|
||||
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &set)
|
||||
if err != nil {
|
||||
if err := syscall.Setrlimit(syscall.RLIMIT_CPU, &set); err != nil {
|
||||
t.Fatalf("Setrlimit: set failed: %#v %v", set, err)
|
||||
}
|
||||
var get syscall.Rlimit
|
||||
err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &get)
|
||||
if err != nil {
|
||||
if err := syscall.Getrlimit(syscall.RLIMIT_CPU, &get); err != nil {
|
||||
t.Fatalf("Getrlimit: get failed: %v", err)
|
||||
}
|
||||
set = rlimit
|
||||
set.Cur = set.Max - 1
|
||||
if (runtime.GOOS == "darwin" || runtime.GOOS == "ios") && set.Cur > 4096 {
|
||||
set.Cur = 4096
|
||||
}
|
||||
if set != get {
|
||||
t.Fatalf("Rlimit: change failed: wanted %#v got %#v", set, get)
|
||||
}
|
||||
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit)
|
||||
if err != nil {
|
||||
if err := syscall.Setrlimit(syscall.RLIMIT_CPU, &rlimit); err != nil {
|
||||
t.Fatalf("Setrlimit: restore failed: %#v %v", rlimit, err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue