diff --git a/unix/syscall_linux_test.go b/unix/syscall_linux_test.go index 76555d40..3625f462 100644 --- a/unix/syscall_linux_test.go +++ b/unix/syscall_linux_test.go @@ -234,9 +234,12 @@ func TestPselect(t *testing.T) { } dur := 2500 * time.Microsecond - ts := unix.NsecToTimespec(int64(dur)) var took time.Duration for { + // On some platforms (e.g. Linux), the passed-in timespec is + // updated by pselect(2). Make sure to reset to the full + // duration in case of an EINTR. + ts := unix.NsecToTimespec(int64(dur)) start := time.Now() n, err := unix.Pselect(0, nil, nil, nil, &ts, nil) took = time.Since(start) @@ -252,8 +255,10 @@ func TestPselect(t *testing.T) { break } - if took < dur { - t.Errorf("Pselect: timeout should have been at least %v, got %v", dur, took) + // On some builder the actual timeout might also be slightly less than the requested. + // Add an acceptable margin to avoid flaky tests. + if took < dur*2/3 { + t.Errorf("Pselect: got %v timeout, expected at least %v", took, dur) } } diff --git a/unix/syscall_unix_test.go b/unix/syscall_unix_test.go index bebc1694..473e7908 100644 --- a/unix/syscall_unix_test.go +++ b/unix/syscall_unix_test.go @@ -537,9 +537,12 @@ func TestSelect(t *testing.T) { } dur := 250 * time.Millisecond - tv := unix.NsecToTimeval(int64(dur)) var took time.Duration for { + // On some platforms (e.g. Linux), the passed-in timeval is + // updated by select(2). Make sure to reset to the full duration + // in case of an EINTR. + tv := unix.NsecToTimeval(int64(dur)) start := time.Now() n, err := unix.Select(0, nil, nil, nil, &tv) took = time.Since(start)