diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2020-12-08 09:29:09 +1300 |
---|---|---|
committer | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2020-12-09 08:55:35 +1300 |
commit | 2553c5f94a5d51c2c5876b31e4c1521ad9be12f6 (patch) | |
tree | fc7b8fe6e578424b15dea0f8b94caa7a72b5c0a1 /test | |
parent | a4a92ae6d99a75e11165ca09c44ccf47cf342047 (diff) | |
download | ruby-2553c5f94a5d51c2c5876b31e4c1521ad9be12f6.tar.gz |
Add support for non-blocking `Process.wait`.
Diffstat (limited to 'test')
-rw-r--r-- | test/fiber/scheduler.rb | 7 | ||||
-rw-r--r-- | test/fiber/test_process.rb | 36 | ||||
-rw-r--r-- | test/ruby/test_process.rb | 6 |
3 files changed, 49 insertions, 0 deletions
diff --git a/test/fiber/scheduler.rb b/test/fiber/scheduler.rb index 7cf0c26459..b3c3eaff59 100644 --- a/test/fiber/scheduler.rb +++ b/test/fiber/scheduler.rb @@ -117,6 +117,13 @@ class Scheduler Process.clock_gettime(Process::CLOCK_MONOTONIC) end + def process_wait(pid, flags) + # This is a very simple way to implement a non-blocking wait: + Thread.new do + Process::Status.wait(pid, flags) + end.value + end + def io_wait(io, events, duration) unless (events & IO::READABLE).zero? @readable[io] = Fiber.current diff --git a/test/fiber/test_process.rb b/test/fiber/test_process.rb new file mode 100644 index 0000000000..c6583cac9b --- /dev/null +++ b/test/fiber/test_process.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true +require 'test/unit' +require_relative 'scheduler' + +class TestFiberProcess < Test::Unit::TestCase + def test_process_wait + Thread.new do + scheduler = Scheduler.new + Fiber.set_scheduler scheduler + + Fiber.schedule do + pid = Process.spawn("true") + Process.wait(pid) + + # TODO test that scheduler was invoked. + + assert_predicate $?, :success? + end + end.join + end + + def test_system + Thread.new do + scheduler = Scheduler.new + Fiber.set_scheduler scheduler + + Fiber.schedule do + system("true") + + # TODO test that scheduler was invoked (currently it's not). + + assert_predicate $?, :success? + end + end.join + end +end diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 65af494bd6..4f96a623e0 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -2492,6 +2492,12 @@ EOS assert_same(Process.last_status, $?) end + def test_last_status_failure + assert_nil system("sad") + assert_not_predicate $?, :success? + assert_equal $?.exitstatus, 127 + end + def test_exec_failure_leaves_no_child assert_raise(Errno::ENOENT) do spawn('inexistent_command') |