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
|
|
|
|
Fiber do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fiber_blocking
|
|
|
|
scheduler = Scheduler.new
|
|
|
|
|
|
|
|
thread = Thread.new do
|
|
|
|
Thread.current.scheduler = scheduler
|
|
|
|
|
|
|
|
# Close is always a blocking operation.
|
|
|
|
IO.pipe.each(&:close)
|
|
|
|
end
|
|
|
|
|
|
|
|
thread.join
|
|
|
|
|
|
|
|
assert_not_empty scheduler.blocking
|
2020-05-23 04:24:29 -04:00
|
|
|
assert_match(/test_scheduler\.rb:\d+:in `close'/, scheduler.blocking.last)
|
2020-05-14 06:10:55 -04:00
|
|
|
end
|
|
|
|
end
|