Add basic Select tests
And Linux CI.
The background here is that I believe Select is broken on Windows.
After this PR is merged I want to add Windows CI as well to prove / disprove that.
Ref: https://github.com/walles/moar/issues/222
I noticed CI isn't running though, maybe GitHub Actions has to be enabled in the project settings or something?
@artbin, would it be possible for you do go test in this branch on Windows?
I'm super interested in whether the tests pass there!
TestSelect_readEmptyPipe fails with The pipe has bytes, should have been ready for reading
Note that TestReadWriteSync fails as well (and fails in master too).
@creack on which platform did all tests fail for you?
I tested on macOS and Linux and they all passed.
Linux, in Docker:
root@68308311032f:/goselect# go test -v ./...
? github.com/creack/goselect/example [no test files]
=== RUN TestReadWriteSync
--- PASS: TestReadWriteSync (1.54s)
=== RUN TestSelect_readEmptyPipe
--- PASS: TestSelect_readEmptyPipe (0.01s)
=== RUN TestSelect_readClosedPipe
--- PASS: TestSelect_readClosedPipe (0.00s)
=== RUN TestSelect_readWrittenPipe
--- PASS: TestSelect_readWrittenPipe (0.00s)
PASS
ok github.com/creack/goselect 1.555s
root@68308311032f:/goselect#
macOS:
~/s/goselect (johan/add-tests|✔) $ go test -v ./...
=== RUN TestReadWriteSync
--- PASS: TestReadWriteSync (1.54s)
=== RUN TestSelect_readEmptyPipe
--- PASS: TestSelect_readEmptyPipe (0.01s)
=== RUN TestSelect_readClosedPipe
--- PASS: TestSelect_readClosedPipe (0.00s)
=== RUN TestSelect_readWrittenPipe
--- PASS: TestSelect_readWrittenPipe (0.00s)
PASS
ok github.com/creack/goselect (cached)
? github.com/creack/goselect/example [no test files]
~/s/goselect (johan/add-tests|✔) $
on windows 10
TestSelect_readEmptyPipefails withThe pipe has bytes, should have been ready for reading
Is the test doing something wrong? Or is the Windows specific code broken?
func TestSelect_readEmptyPipe(t *testing.T) {
r, w, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
defer func() {
if err := w.Close(); err != nil {
t.Fatal(err)
}
if err := r.Close(); err != nil {
t.Fatal(err)
}
}()
rFDSet := &FDSet{}
rFDSet.Set(r.Fd())
max := r.Fd()
if err := Select(int(max+1), rFDSet, nil, nil, 10*time.Millisecond); err != nil {
t.Fatalf("select call failed: %s", err)
}
if rFDSet.IsSet(r.Fd()) {
t.Fatal("Nothing written, the pipe should not have been ready for reading")
}
}
Having this PR open provides no value, closing.
As long as goselect doesn't work on Windows these tests won't pass, and this PR can't be merged.