From af1c587546c34190721bb8b72e86985e9b79bdc6 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Fri, 12 Feb 2021 15:06:07 +1300 Subject: [PATCH] Improve timeout tests. --- test/fiber/test_timeout.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/fiber/test_timeout.rb b/test/fiber/test_timeout.rb index 127e4b0084..c17092b8e6 100644 --- a/test/fiber/test_timeout.rb +++ b/test/fiber/test_timeout.rb @@ -14,7 +14,7 @@ class TestFiberTimeout < Test::Unit::TestCase Fiber.schedule do begin - Timeout.timeout(0.01) do + Timeout.timeout(0.001) do sleep(1) end rescue @@ -27,4 +27,23 @@ class TestFiberTimeout < Test::Unit::TestCase assert_kind_of(Timeout::Error, error) end + + MESSAGE = "Hello World" + + def test_timeout_on_main_fiber + message = nil + + thread = Thread.new do + scheduler = Scheduler.new + Fiber.set_scheduler scheduler + + Timeout.timeout(1) do + message = MESSAGE + end + end + + thread.join + + assert_equal MESSAGE, message + end end