goselect icon indicating copy to clipboard operation
goselect copied to clipboard

Add basic Select tests

Open walles opened this issue 1 year ago • 6 comments

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?

walles avatar Jul 01 '24 05:07 walles

@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!

walles avatar Jul 01 '24 05:07 walles

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 avatar Jul 01 '24 12:07 creack

@creack on which platform did all tests fail for you?

I tested on macOS and Linux and they all passed.

walles avatar Jul 01 '24 17:07 walles

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|✔) $

walles avatar Jul 01 '24 17:07 walles

on windows 10

creack avatar Jul 01 '24 18:07 creack

TestSelect_readEmptyPipe fails with The 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")
	}
}

walles avatar Jul 01 '24 18:07 walles

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.

walles avatar Apr 09 '25 04:04 walles