From 236baca6791e3758b28d82d8e444806c7e5448a3 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 20 Dec 2017 12:15:19 +0100 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- unix/syscall_linux_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/unix/syscall_linux_test.go b/unix/syscall_linux_test.go index 2b66ad30..ea9562fe 100644 --- a/unix/syscall_linux_test.go +++ b/unix/syscall_linux_test.go @@ -182,6 +182,39 @@ func TestSelect(t *testing.T) { if err != nil { 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) {