//go:build linux || darwin package containment import ( "testing" "time" "golang.org/x/sys/unix" ) func TestPollRetriesEINTR(t *testing.T) { calls := 0 poll := func([]unix.PollFd, int) (int, error) { calls++ if calls <= 2 { return 0, unix.EINTR } return 1, nil } n, e := pollRetry(nil, 0, poll) if n != 1 || e != nil || calls != 3 { t.Fatalf("interrupted poll not retried: n=%d err=%v calls=%d", n, e, calls) } } func TestPollRetryBoundsZeroTimeout(t *testing.T) { calls := 0 poll := func([]unix.PollFd, int) (int, error) { calls++ if calls > 10*zeroTimeoutTries { return 0, nil // without a cap, stop here so the assertion reports it } return 0, unix.EINTR } n, e := pollRetry(nil, 0, poll) if n != 0 || e != unix.EINTR || calls != zeroTimeoutTries { t.Fatalf("endless interruption not bounded: n=%d err=%v calls=%d", n, e, calls) } } func TestPollRetryKeepsDeadline(t *testing.T) { poll := func([]unix.PollFd, int) (int, error) { time.Sleep(30 * time.Millisecond) return 0, unix.EINTR } start := time.Now() n, e := pollRetry(nil, 100*time.Millisecond, poll) took := time.Since(start) if n != 0 || e != nil || took > 200*time.Millisecond { t.Fatalf("retries outlived the timeout: n=%d err=%v after %v", n, e, took) } }