summaryrefslogtreecommitdiff
path: root/test/scheduler/test_fiber.rb
blob: 3452591cd96e6e1ed1ee07b7fe8347a875e385e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true
require 'test/unit'
require_relative 'scheduler'

class TestSchedulerFiber < Test::Unit::TestCase
  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
    assert_match /test_fiber.rb:\d+:in `close'/, scheduler.blocking.last
  end
end