mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-03 15:47:35 -04:00
unix: add timeout tests for Select and Pselect on Linux
Test for correct timeout behavior of Select and Pselect Updates golang/go#22246 Change-Id: I86d1804c6ddf5072e93f3ef4f359198e732fae94 Reviewed-on: https://go-review.googlesource.com/84955 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
committed by
Tobias Klauser
parent
571f7bbbe0
commit
236baca679
@@ -182,6 +182,39 @@ func TestSelect(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Select: %v", err)
|
t.Fatalf("Select: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dur := 150 * time.Millisecond
|
||||||
|
tv := unix.NsecToTimeval(int64(dur))
|
||||||
|
start := time.Now()
|
||||||
|
_, err = unix.Select(0, nil, nil, nil, &tv)
|
||||||
|
took := time.Since(start)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Select: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if took < dur {
|
||||||
|
t.Errorf("Select: timeout should have been at least %v, got %v", dur, took)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPselect(t *testing.T) {
|
||||||
|
_, err := unix.Pselect(0, nil, nil, nil, &unix.Timespec{Sec: 0, Nsec: 0}, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Pselect: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
dur := 2500 * time.Microsecond
|
||||||
|
ts := unix.NsecToTimespec(int64(dur))
|
||||||
|
start := time.Now()
|
||||||
|
_, err = unix.Pselect(0, nil, nil, nil, &ts, nil)
|
||||||
|
took := time.Since(start)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Pselect: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if took < dur {
|
||||||
|
t.Errorf("Pselect: timeout should have been at least %v, got %v", dur, took)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFstatat(t *testing.T) {
|
func TestFstatat(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user