summaryrefslogtreecommitdiff
path: root/test/fiber/test_timeout.rb
blob: b974aa0e352044cf0529750c93e840a1729e268b (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
30
# frozen_string_literal: true
require 'test/unit'
require_relative 'scheduler'

require 'timeout'

class TestFiberTimeout < Test::Unit::TestCase
  def test_timeout_raise
    error = nil

    thread = Thread.new do
      scheduler = Scheduler.new
      Fiber.set_scheduler scheduler

      Fiber.schedule do
        begin
          Timeout.timeout(0.01) do
            sleep(1)
          end
        rescue
          error = $!
        end
      end
    end

    thread.join

    assert_kind_of(Timeout::Error, error)
  end
end