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_scheduler.rb
2020-10-01 13:47:57 +09:00

60 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require 'test/unit'
require_relative 'scheduler'
class TestFiberScheduler < Test::Unit::TestCase
def test_fiber_without_scheduler
# Cannot create fiber without scheduler.
assert_raise RuntimeError do
Fiber.schedule do
end
end
end
def test_closed_at_thread_exit
scheduler = Scheduler.new
thread = Thread.new do
Thread.current.scheduler = scheduler
end
thread.join
assert scheduler.closed?
end
def test_closed_when_set_to_nil
scheduler = Scheduler.new
thread = Thread.new do
Thread.current.scheduler = scheduler
Thread.current.scheduler = nil
assert scheduler.closed?
end
thread.join
end
def test_close_at_exit
assert_in_out_err %W[-I#{__dir__} -], <<-RUBY, ['Running Fiber'], [], success: true
require 'scheduler'
scheduler = Scheduler.new
Thread.current.scheduler = scheduler
Fiber.schedule do
sleep(0)
puts "Running Fiber"
end
RUBY
end
def test_optional_close
thread = Thread.new do
Thread.current.scheduler = Object.new
end
thread.join
end
end