From 5e75280c8edcd0f3c8f79d0c532cbfd18074886a Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Tue, 29 Jun 2021 21:58:31 +1200 Subject: Add basic test for updated IO wait functions. --- test/-ext-/wait/test_wait.rb | 32 ++++++++++++++ .../wait_for_single_fd/test_wait_for_single_fd.rb | 49 ---------------------- 2 files changed, 32 insertions(+), 49 deletions(-) create mode 100644 test/-ext-/wait/test_wait.rb delete mode 100644 test/-ext-/wait_for_single_fd/test_wait_for_single_fd.rb (limited to 'test/-ext-') diff --git a/test/-ext-/wait/test_wait.rb b/test/-ext-/wait/test_wait.rb new file mode 100644 index 0000000000..79127c041b --- /dev/null +++ b/test/-ext-/wait/test_wait.rb @@ -0,0 +1,32 @@ +# 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 + r, w = IO.pipe + r.close + + IO.for_fd(w.fileno).close + + assert_raise(Errno::EBADF) do + IO.io_wait(w, IO::WRITABLE, nil) + end + 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 diff --git a/test/-ext-/wait_for_single_fd/test_wait_for_single_fd.rb b/test/-ext-/wait_for_single_fd/test_wait_for_single_fd.rb deleted file mode 100644 index 777e9d14dd..0000000000 --- a/test/-ext-/wait_for_single_fd/test_wait_for_single_fd.rb +++ /dev/null @@ -1,49 +0,0 @@ -# frozen_string_literal: false -require 'test/unit' - -class TestWaitForSingleFD < Test::Unit::TestCase - require '-test-/wait_for_single_fd' - - def test_wait_for_valid_fd - IO.pipe do |r,w| - rc = IO.wait_for_single_fd(w.fileno, RB_WAITFD_OUT, nil) - assert_equal RB_WAITFD_OUT, rc - end - end - - def test_wait_for_invalid_fd - # Negative FDs should not cause NoMemoryError or segfault when - # using select(). For now, match the poll() implementation - # used on Linux, which sleeps the given amount of time given - # when fd is negative (as documented in the Linux poll(2) manpage) - assert_equal 0, IO.wait_for_single_fd(-999, RB_WAITFD_IN, 0) - assert_equal 0, IO.wait_for_single_fd(-1, RB_WAITFD_OUT, 0) - - # FreeBSD 8.2 or prior sticks this - # http://bugs.ruby-lang.org/issues/5524 - if /freebsd([\d\.]+)/ =~ RUBY_PLATFORM - ver = $1.to_r - skip 'FreeBSD <= 8.2' if ver <= 8.2r - end - IO.pipe do |r,w| - wfd = w.fileno - w.close - assert_raise(Errno::EBADF) do - IO.wait_for_single_fd(wfd, RB_WAITFD_OUT, nil) - end - end - end - - def test_wait_for_closed_pipe - IO.pipe do |r,w| - w.close - rc = IO.wait_for_single_fd(r.fileno, RB_WAITFD_IN, nil) - assert_equal RB_WAITFD_IN, rc - end - end - - def test_wait_for_kqueue - skip 'no kqueue' unless IO.respond_to?(:kqueue_test_wait) - assert_equal RB_WAITFD_IN, IO.kqueue_test_wait - end -end -- cgit v1.2.3