From f221eed1c01e0ccb9f05b340c5f19c8fffd228ee Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Thu, 11 Nov 2021 16:09:14 -0500 Subject: [PATCH] unix: in TestSelect, only error for an early wakeup on Linux On Linux, 'man 2 select' explicitly lists the conditions under which select may return before the timeout interval. Most other platforms make no such guarantee, so do not test for it on those platforms. Fixes golang/go#36409 Change-Id: I194a34af3132a7db7fc186dec9de67fa6dd0bfae Reviewed-on: https://go-review.googlesource.com/c/sys/+/363455 Trust: Bryan C. Mills Run-TryBot: Bryan C. Mills TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor --- unix/syscall_unix_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/unix/syscall_unix_test.go b/unix/syscall_unix_test.go index c1478ed2..cfcdd0e1 100644 --- a/unix/syscall_unix_test.go +++ b/unix/syscall_unix_test.go @@ -562,10 +562,17 @@ func TestSelect(t *testing.T) { break } - // On some BSDs 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("Select: got %v timeout, expected at least %v", took, dur) + // On some platforms (e.g. NetBSD) the actual timeout might be arbitrarily + // less than requested. However, Linux in particular promises to only return + // early if a file descriptor becomes ready (not applicable here), or the call + // is interrupted by a signal handler (explicitly retried in the loop above), + // or the timeout expires. + if took < dur { + if runtime.GOOS == "linux" { + t.Errorf("Select: slept for %v, expected %v", took, dur) + } else { + t.Logf("Select: slept for %v, requested %v", took, dur) + } } rr, ww, err := os.Pipe()