2021-06-29 05:58:31 -04:00
|
|
|
# frozen_string_literal: false
|
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
class TestWait < Test::Unit::TestCase
|
|
|
|
require '-test-/wait'
|
|
|
|
|
|
|
|
def test_wait_for_valid_fd
|
|
|
|
IO.pipe do |r,w|
|
|
|
|
rc = IO.io_wait(w, IO::WRITABLE, nil)
|
|
|
|
assert_equal IO::WRITABLE, rc
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_wait_for_invalid_fd
|
2021-10-25 22:35:57 -04:00
|
|
|
assert_separately [], <<~'RUBY'
|
|
|
|
require '-test-/wait'
|
2021-06-29 05:58:31 -04:00
|
|
|
|
2021-10-25 22:35:57 -04:00
|
|
|
r, w = IO.pipe
|
|
|
|
r.close
|
2021-06-29 05:58:31 -04:00
|
|
|
|
2021-10-25 22:35:57 -04:00
|
|
|
IO.for_fd(w.fileno).close
|
|
|
|
|
|
|
|
assert_raise(Errno::EBADF) do
|
|
|
|
IO.io_wait(w, IO::WRITABLE, nil)
|
|
|
|
end
|
|
|
|
RUBY
|
2021-06-29 05:58:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_wait_for_closed_pipe
|
|
|
|
IO.pipe do |r,w|
|
|
|
|
w.close
|
|
|
|
rc = IO.io_wait(r, IO::READABLE, nil)
|
|
|
|
assert_equal IO::READABLE, rc
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|