2020-05-14 06:10:55 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'test/unit'
|
|
|
|
require_relative 'scheduler'
|
|
|
|
|
2020-05-23 03:43:58 -04:00
|
|
|
class TestFiberScheduler < Test::Unit::TestCase
|
2020-05-14 06:10:55 -04:00
|
|
|
def test_fiber_without_scheduler
|
|
|
|
# Cannot create fiber without scheduler.
|
|
|
|
assert_raise RuntimeError do
|
2020-08-20 08:52:36 -04:00
|
|
|
Fiber.schedule do
|
2020-05-14 06:10:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-09-19 19:34:02 -04:00
|
|
|
|
|
|
|
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
|
2020-05-14 06:10:55 -04:00
|
|
|
end
|