fdlimit_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2016 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package fdlimit
  17. import (
  18. "fmt"
  19. "testing"
  20. )
  21. // TestFileDescriptorLimits simply tests whether the file descriptor allowance
  22. // per this process can be retrieved.
  23. func TestFileDescriptorLimits(t *testing.T) {
  24. target := 4096
  25. hardlimit, err := Maximum()
  26. if err != nil {
  27. t.Fatal(err)
  28. }
  29. if hardlimit < target {
  30. t.Skip(fmt.Sprintf("system limit is less than desired test target: %d < %d", hardlimit, target))
  31. }
  32. if limit, err := Current(); err != nil || limit <= 0 {
  33. t.Fatalf("failed to retrieve file descriptor limit (%d): %v", limit, err)
  34. }
  35. if _, err := Raise(uint64(target)); err != nil {
  36. t.Fatalf("failed to raise file allowance")
  37. }
  38. if limit, err := Current(); err != nil || limit < target {
  39. t.Fatalf("failed to retrieve raised descriptor limit (have %v, want %v): %v", limit, target, err)
  40. }
  41. }