1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/fiber/test_thread.rb
Samuel Williams 5f69a7f604
Expose scheduler as public interface & bug fixes. (#3945)
* Rename `rb_scheduler` to `rb_fiber_scheduler`.

* Use public interface if available.

* Use `rb_check_funcall` where possible.

* Don't use `unblock` unless the fiber was non-blocking.
2021-02-09 19:39:56 +13:00

45 lines
922 B
Ruby

# frozen_string_literal: true
require "test/unit"
require_relative 'scheduler'
class TestFiberThread < Test::Unit::TestCase
def test_thread_join
thread = Thread.new do
scheduler = Scheduler.new
Fiber.set_scheduler scheduler
result = nil
Fiber.schedule do
result = Thread.new{:done}.value
end
scheduler.run
result
end
assert_equal :done, thread.value
end
def test_thread_join_blocking
thread = Thread.new do
scheduler = Scheduler.new
Fiber.set_scheduler scheduler
result = nil
Fiber.schedule do
Fiber.new(blocking: true) do
# This can deadlock if the blocking state is not taken into account:
Thread.new do
sleep(0)
result = :done
end.join
end.resume
end
scheduler.run
result
end
assert_equal :done, thread.value
end
end