Skip to content

Commit

Permalink
Remove EINTR from the test cases (handled at syscall layer)
Browse files Browse the repository at this point in the history
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
  • Loading branch information
evacchi committed Aug 2, 2023
1 parent c2697a5 commit bbb7b33
Showing 1 changed file with 27 additions and 49 deletions.
76 changes: 27 additions & 49 deletions internal/sysfs/poll_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,41 @@ import (
"testing"
"time"

"github.com/tetratelabs/wazero/experimental/sys"
"github.com/tetratelabs/wazero/internal/testing/require"
)

func Test_poll(t *testing.T) {
t.Run("should return immediately with no fds and duration 0", func(t *testing.T) {
for {
n, err := _poll([]pollFd{}, 0)
if err == sys.EINTR {
t.Logf("Select interrupted")
continue
}
require.EqualErrno(t, 0, err)
require.Equal(t, 0, n)
return
}
n, err := _poll([]pollFd{}, 0)
require.EqualErrno(t, 0, err)
require.Equal(t, 0, n)
})

t.Run("should wait for the given duration", func(t *testing.T) {
dur := int32(250)
var took time.Duration
for {

// On some platforms (e.g. Linux), the passed-in timeval is
// updated by select(2). We are not accounting for this
// in our implementation.
start := time.Now()
n, err := _poll([]pollFd{}, dur)
took = time.Since(start)
if err == sys.EINTR {
t.Logf("Select interrupted after %v", took)
continue
}
require.EqualErrno(t, 0, err)
require.Equal(t, 0, n)

// On some platforms the actual timeout might be arbitrarily
// less than requested.
if took < time.Duration(dur)*time.Millisecond {
if runtime.GOOS == "linux" {
// Linux promises to only return early if a file descriptor
// becomes ready (not applicable here), or the call
// is interrupted by a signal handler (explicitly retried in the loop above),
// or the timeout expires.
t.Errorf("Select: slept for %v, expected %v", took, dur)
} else {
t.Logf("Select: slept for %v, requested %v", took, dur)
}
// On some platforms (e.g. Linux), the passed-in timeval is
// updated by select(2). We are not accounting for this
// in our implementation.
start := time.Now()
n, err := _poll([]pollFd{}, dur)
took = time.Since(start)
require.EqualErrno(t, 0, err)
require.Equal(t, 0, n)

// On some platforms the actual timeout might be arbitrarily
// less than requested.
if took < time.Duration(dur)*time.Millisecond {
if runtime.GOOS == "linux" {
// Linux promises to only return early if a file descriptor
// becomes ready (not applicable here), or the call
// is interrupted by a signal handler (explicitly retried in the loop above),
// or the timeout expires.
t.Errorf("Select: slept for %v, expected %v", took, dur)
} else {
t.Logf("Select: slept for %v, requested %v", took, dur)
}
return
}
})

Expand All @@ -70,16 +55,9 @@ func Test_poll(t *testing.T) {
_, err = ww.Write([]byte("TEST"))
require.NoError(t, err)

for {
fds := []pollFd{newPollFd(rr.Fd(), _POLLIN, 0)}
if err == sys.EINTR {
t.Log("Select interrupted")
continue
}
n, err := _poll(fds, 0)
require.EqualErrno(t, 0, err)
require.Equal(t, 1, n)
return
}
fds := []pollFd{newPollFd(rr.Fd(), _POLLIN, 0)}
n, err := _poll(fds, 0)
require.EqualErrno(t, 0, err)
require.Equal(t, 1, n)
})
}

0 comments on commit bbb7b33

Please sign in to comment.