From 8281f8fd067017ac909bd16a66e64cfdfed06bc8 Mon Sep 17 00:00:00 2001 From: John Bachir Date: Mon, 3 Jul 2023 05:26:40 -0400 Subject: [PATCH] [ruby/timeout] Test that work is done in the same thread/fiber as the caller (https://github.com/ruby/timeout/pull/34) * see discussion in https://github.com/ruby/timeout/pull/30#issuecomment-1616179651 --- test/test_timeout.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test_timeout.rb b/test/test_timeout.rb index 236883aab4..0a8dc45cc3 100644 --- a/test/test_timeout.rb +++ b/test/test_timeout.rb @@ -4,6 +4,15 @@ require 'timeout' class TestTimeout < Test::Unit::TestCase + def test_work_is_done_in_same_thread_as_caller + assert_equal Thread.current, Timeout.timeout(10){ Thread.current } + end + + def test_work_is_done_in_same_fiber_as_caller + require 'fiber' # needed for ruby 3.0 and lower + assert_equal Fiber.current, Timeout.timeout(10){ Fiber.current } + end + def test_non_timing_out_code_is_successful assert_nothing_raised do assert_equal :ok, Timeout.timeout(1){ :ok }