summaryrefslogtreecommitdiff
path: root/test/fiber
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-12-08 09:29:09 +1300
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-12-09 08:55:35 +1300
commit2553c5f94a5d51c2c5876b31e4c1521ad9be12f6 (patch)
treefc7b8fe6e578424b15dea0f8b94caa7a72b5c0a1 /test/fiber
parenta4a92ae6d99a75e11165ca09c44ccf47cf342047 (diff)
Add support for non-blocking `Process.wait`.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3853
Diffstat (limited to 'test/fiber')
-rw-r--r--test/fiber/scheduler.rb7
-rw-r--r--test/fiber/test_process.rb36
2 files changed, 43 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