Browse Source

unix: add TestSelect for *BSD

Change-Id: I9aa4ac170c361e56e36bded0cc13fb99346f70cf
Reviewed-on: https://go-review.googlesource.com/85275
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Tobias Klauser 8 years ago
parent
commit
df29b91272
1 changed files with 23 additions and 0 deletions
  1. 23 0
      unix/syscall_bsd_test.go

+ 23 - 0
unix/syscall_bsd_test.go

@@ -10,6 +10,7 @@ import (
 	"os/exec"
 	"runtime"
 	"testing"
+	"time"
 
 	"golang.org/x/sys/unix"
 )
@@ -50,6 +51,28 @@ func TestGetfsstat(t *testing.T) {
 	}
 }
 
+func TestSelect(t *testing.T) {
+	err := unix.Select(0, nil, nil, nil, &unix.Timeval{Sec: 0, Usec: 0})
+	if err != nil {
+		t.Fatalf("Select: %v", err)
+	}
+
+	dur := 250 * 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)
+	}
+
+	// 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: timeout should have been at least %v, got %v", dur, took)
+	}
+}
+
 func TestSysctlRaw(t *testing.T) {
 	if runtime.GOOS == "openbsd" {
 		t.Skip("kern.proc.pid does not exist on OpenBSD")