mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-05 16:47:27 -04:00
unix: don't fail TestSelect on EINTR from Select
Change-Id: Ie162966c830ffd86947cf4f04532a7f6741a5587 Reviewed-on: https://go-review.googlesource.com/c/sys/+/207861 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
committed by
Tobias Klauser
parent
6bfc516c86
commit
76d669a226
@@ -513,25 +513,38 @@ func TestPoll(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSelect(t *testing.T) {
|
func TestSelect(t *testing.T) {
|
||||||
|
for {
|
||||||
n, err := unix.Select(0, nil, nil, nil, &unix.Timeval{Sec: 0, Usec: 0})
|
n, err := unix.Select(0, nil, nil, nil, &unix.Timeval{Sec: 0, Usec: 0})
|
||||||
if err != nil {
|
if err == unix.EINTR {
|
||||||
|
t.Logf("Select interrupted")
|
||||||
|
continue
|
||||||
|
} else if err != nil {
|
||||||
t.Fatalf("Select: %v", err)
|
t.Fatalf("Select: %v", err)
|
||||||
}
|
}
|
||||||
if n != 0 {
|
if n != 0 {
|
||||||
t.Fatalf("Select: got %v ready file descriptors, expected 0", n)
|
t.Fatalf("Select: got %v ready file descriptors, expected 0", n)
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
dur := 250 * time.Millisecond
|
dur := 250 * time.Millisecond
|
||||||
tv := unix.NsecToTimeval(int64(dur))
|
tv := unix.NsecToTimeval(int64(dur))
|
||||||
|
var took time.Duration
|
||||||
|
for {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
n, err = unix.Select(0, nil, nil, nil, &tv)
|
n, err := unix.Select(0, nil, nil, nil, &tv)
|
||||||
took := time.Since(start)
|
took = time.Since(start)
|
||||||
if err != nil {
|
if err == unix.EINTR {
|
||||||
|
t.Logf("Select interrupted after %v", took)
|
||||||
|
continue
|
||||||
|
} else if err != nil {
|
||||||
t.Fatalf("Select: %v", err)
|
t.Fatalf("Select: %v", err)
|
||||||
}
|
}
|
||||||
if n != 0 {
|
if n != 0 {
|
||||||
t.Fatalf("Select: got %v ready file descriptors, expected 0", n)
|
t.Fatalf("Select: got %v ready file descriptors, expected 0", n)
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
// On some BSDs the actual timeout might also be slightly less than the requested.
|
// On some BSDs the actual timeout might also be slightly less than the requested.
|
||||||
// Add an acceptable margin to avoid flaky tests.
|
// Add an acceptable margin to avoid flaky tests.
|
||||||
@@ -554,13 +567,19 @@ func TestSelect(t *testing.T) {
|
|||||||
fd := int(rr.Fd())
|
fd := int(rr.Fd())
|
||||||
rFdSet.Set(fd)
|
rFdSet.Set(fd)
|
||||||
|
|
||||||
n, err = unix.Select(fd+1, rFdSet, nil, nil, nil)
|
for {
|
||||||
if err != nil {
|
n, err := unix.Select(fd+1, rFdSet, nil, nil, nil)
|
||||||
|
if err == unix.EINTR {
|
||||||
|
t.Log("Select interrupted")
|
||||||
|
continue
|
||||||
|
} else if err != nil {
|
||||||
t.Fatalf("Select: %v", err)
|
t.Fatalf("Select: %v", err)
|
||||||
}
|
}
|
||||||
if n != 1 {
|
if n != 1 {
|
||||||
t.Fatalf("Select: got %v ready file descriptors, expected 1", n)
|
t.Fatalf("Select: got %v ready file descriptors, expected 1", n)
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetwd(t *testing.T) {
|
func TestGetwd(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user