Files
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

57 lines
1.3 KiB
Go

//go:build !windows
package daemon
import (
"errors"
"syscall"
"testing"
)
func TestRaiseFDLimit_RaisesSoftCapAndDoesNotShrink(t *testing.T) {
var before syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &before); err != nil {
t.Fatalf("Getrlimit: %v", err)
}
got, err := RaiseFDLimit()
if err != nil {
t.Fatalf("RaiseFDLimit: %v", err)
}
if got.Soft < uint64(before.Cur) {
t.Fatalf("soft cap shrank: before=%d after=%d", before.Cur, got.Soft)
}
var after syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &after); err != nil {
t.Fatalf("Getrlimit (after): %v", err)
}
if uint64(after.Cur) != got.Soft {
t.Fatalf("returned soft (%d) does not match observed soft (%d)", got.Soft, after.Cur)
}
}
func TestIsEMFILE(t *testing.T) {
if !isEMFILE(syscall.EMFILE) {
t.Fatal("EMFILE should be detected")
}
if !isEMFILE(syscall.ENFILE) {
t.Fatal("ENFILE should be detected")
}
wrapped := &fdErr{err: syscall.EMFILE}
if !isEMFILE(wrapped) {
t.Fatal("wrapped EMFILE should be detected via errors.Is")
}
if isEMFILE(syscall.EACCES) {
t.Fatal("EACCES is not an FD-exhaustion error")
}
if isEMFILE(errors.New("boom")) {
t.Fatal("plain error must not match")
}
}
type fdErr struct{ err error }
func (e *fdErr) Error() string { return e.err.Error() }
func (e *fdErr) Unwrap() error { return e.err }