test(conn): build the server tests on every Unix
syscall.FdSet has no Bits field on FreeBSD, so the select-based wait only exists on Linux; other platforms skip the poll-loop test.
- commit
- 0885f41541dec41c19b39c73126e83ce7cf1ff9e
- author
- brice · · 2026-10-14 21:35 UTC
- parent
- 69ad4ea
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
3 files · +14 -19
M server_test.go +4 -1
| @@ -1,6 +1,7 @@ | |||
| 1 | 1 | package zerobus | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | + | "errors" | |
| 4 | 5 | "net" | |
| 5 | 6 | "path/filepath" | |
| 6 | 7 | "testing" | |
| @@ -228,7 +229,9 @@ func waitReadable(t *testing.T, c *Conn) { | |||
| 228 | 229 | if err := rc.Control(func(f uintptr) { fd = int(f) }); err != nil { | |
| 229 | 230 | t.Fatal(err) | |
| 230 | 231 | } | |
| 231 | - | if err := waitFd(fd, 5*time.Second); err != nil { | |
| 232 | + | if err := waitFd(fd, 5*time.Second); errors.Is(err, errNoWaitFd) { | |
| 233 | + | t.Skip(err) | |
| 234 | + | } else if err != nil { | |
| 232 | 235 | t.Fatal(err) | |
| 233 | 236 | } | |
| 234 | 237 | } | |
| @@ -1,6 +1,7 @@ | |||||
| 1 | package zerobus | 1 | package zerobus | ||
| 2 | 2 | ||||
| 3 | import ( | 3 | import ( | ||
| 4 | + | "errors" | |||
| 4 | "net" | 5 | "net" | ||
| 5 | "path/filepath" | 6 | "path/filepath" | ||
| 6 | "testing" | 7 | "testing" | ||
| @@ -228,7 +229,9 @@ func waitReadable(t *testing.T, c *Conn) { | |||||
| 228 | if err := rc.Control(func(f uintptr) { fd = int(f) }); err != nil { | 229 | if err := rc.Control(func(f uintptr) { fd = int(f) }); err != nil { | ||
| 229 | t.Fatal(err) | 230 | t.Fatal(err) | ||
| 230 | } | 231 | } | ||
| 231 | - | if err := waitFd(fd, 5*time.Second); err != nil { | 232 | + | if err := waitFd(fd, 5*time.Second); errors.Is(err, errNoWaitFd) { |
| 233 | + | t.Skip(err) | |||
| 234 | + | } else if err != nil { | |||
| 232 | t.Fatal(err) | 235 | t.Fatal(err) | ||
| 233 | } | 236 | } | ||
| 234 | } | 237 | } | ||
M waitfd_linux_test.go +4 -0
| @@ -1,12 +1,16 @@ | |||
| 1 | 1 | package zerobus | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | + | "errors" | |
| 4 | 5 | "fmt" | |
| 5 | 6 | "syscall" | |
| 6 | 7 | "time" | |
| 7 | 8 | "unsafe" | |
| 8 | 9 | ) | |
| 9 | 10 | ||
| 11 | + | // errNoWaitFd is returned where waitFd is not supported; never on Linux. | |
| 12 | + | var errNoWaitFd = errors.New("waitFd: not supported on this platform") | |
| 13 | + | ||
| 10 | 14 | // waitFd blocks until fd is readable or the timeout passes, as a poll loop | |
| 11 | 15 | // does. | |
| 12 | 16 | func waitFd(fd int, timeout time.Duration) error { | |
| @@ -1,12 +1,16 @@ | |||||
| 1 | package zerobus | 1 | package zerobus | ||
| 2 | 2 | ||||
| 3 | import ( | 3 | import ( | ||
| 4 | + | "errors" | |||
| 4 | "fmt" | 5 | "fmt" | ||
| 5 | "syscall" | 6 | "syscall" | ||
| 6 | "time" | 7 | "time" | ||
| 7 | "unsafe" | 8 | "unsafe" | ||
| 8 | ) | 9 | ) | ||
| 9 | 10 | ||||
| 11 | + | // errNoWaitFd is returned where waitFd is not supported; never on Linux. | |||
| 12 | + | var errNoWaitFd = errors.New("waitFd: not supported on this platform") | |||
| 13 | + | ||||
| 10 | // waitFd blocks until fd is readable or the timeout passes, as a poll loop | 14 | // waitFd blocks until fd is readable or the timeout passes, as a poll loop | ||
| 11 | // does. | 15 | // does. | ||
| 12 | func waitFd(fd int, timeout time.Duration) error { | 16 | func waitFd(fd int, timeout time.Duration) error { | ||
M waitfd_other_test.go +6 -18
| @@ -3,24 +3,12 @@ | |||
| 3 | 3 | package zerobus | |
| 4 | 4 | ||
| 5 | 5 | import ( | |
| 6 | - | "fmt" | |
| 7 | - | "syscall" | |
| 6 | + | "errors" | |
| 8 | 7 | "time" | |
| 9 | - | "unsafe" | |
| 10 | 8 | ) | |
| 11 | 9 | ||
| 12 | - | // waitFd blocks until fd is readable or the timeout passes, as a poll loop | |
| 13 | - | // does. syscall.Select returns only an error outside Linux. | |
| 14 | - | func waitFd(fd int, timeout time.Duration) error { | |
| 15 | - | var set syscall.FdSet | |
| 16 | - | bits := int(unsafe.Sizeof(set.Bits[0])) * 8 | |
| 17 | - | set.Bits[fd/bits] |= 1 << (uint(fd) % uint(bits)) | |
| 18 | - | tv := syscall.NsecToTimeval(timeout.Nanoseconds()) | |
| 19 | - | if err := syscall.Select(fd+1, &set, nil, nil, &tv); err != nil { | |
| 20 | - | return fmt.Errorf("select: %v", err) | |
| 21 | - | } | |
| 22 | - | if set.Bits[fd/bits]&(1<<(uint(fd)%uint(bits))) == 0 { | |
| 23 | - | return fmt.Errorf("select: fd %d not readable after %v", fd, timeout) | |
| 24 | - | } | |
| 25 | - | return nil | |
| 26 | - | } | |
| 10 | + | // errNoWaitFd means the platform has no waitFd: syscall.FdSet differs | |
| 11 | + | // between the BSDs and Darwin, and the poll tests only run on Linux. | |
| 12 | + | var errNoWaitFd = errors.New("waitFd: not supported on this platform") | |
| 13 | + | ||
| 14 | + | func waitFd(int, time.Duration) error { return errNoWaitFd } | |
| @@ -3,24 +3,12 @@ | |||||
| 3 | package zerobus | 3 | package zerobus | ||
| 4 | 4 | ||||
| 5 | import ( | 5 | import ( | ||
| 6 | - | "fmt" | 6 | + | "errors" |
| 7 | - | "syscall" | |||
| 8 | "time" | 7 | "time" | ||
| 9 | - | "unsafe" | |||
| 10 | ) | 8 | ) | ||
| 11 | 9 | ||||
| 12 | - | // waitFd blocks until fd is readable or the timeout passes, as a poll loop | 10 | + | // errNoWaitFd means the platform has no waitFd: syscall.FdSet differs |
| 13 | - | // does. syscall.Select returns only an error outside Linux. | 11 | + | // between the BSDs and Darwin, and the poll tests only run on Linux. |
| 14 | - | func waitFd(fd int, timeout time.Duration) error { | 12 | + | var errNoWaitFd = errors.New("waitFd: not supported on this platform") |
| 15 | - | var set syscall.FdSet | 13 | + | |
| 16 | - | bits := int(unsafe.Sizeof(set.Bits[0])) * 8 | 14 | + | func waitFd(int, time.Duration) error { return errNoWaitFd } |
| 17 | - | set.Bits[fd/bits] |= 1 << (uint(fd) % uint(bits)) | |||
| 18 | - | tv := syscall.NsecToTimeval(timeout.Nanoseconds()) | |||
| 19 | - | if err := syscall.Select(fd+1, &set, nil, nil, &tv); err != nil { | |||
| 20 | - | return fmt.Errorf("select: %v", err) | |||
| 21 | - | } | |||
| 22 | - | if set.Bits[fd/bits]&(1<<(uint(fd)%uint(bits))) == 0 { | |||
| 23 | - | return fmt.Errorf("select: fd %d not readable after %v", fd, timeout) | |||
| 24 | - | } | |||
| 25 | - | return nil | |||
| 26 | - | } | |||