From 3e42aa4d847ed9cf5ea4dab390ef2dc33fbb352e Mon Sep 17 00:00:00 2001 From: John Bachir Date: Tue, 4 Jul 2023 15:45:28 -0400 Subject: [PATCH] nested exception tests for discussion --- test/test_timeout.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/test_timeout.rb b/test/test_timeout.rb index 0a8dc45..27b34de 100644 --- a/test/test_timeout.rb +++ b/test/test_timeout.rb @@ -63,6 +63,42 @@ def test_nested_timeout assert_nil a end + class MyNewErrorOuter < StandardError; end + class MyNewErrorInner < StandardError; end + + # DOES NOT fail with + # - raise new(message) if exc.equal?(e) + # + raise new(message) if exc.class == e.class + def test_nested_timeout_error_identity + begin + Timeout.timeout(0.1, MyNewErrorOuter) { + Timeout.timeout(1, MyNewErrorInner) { + nil while true + } + } + rescue => e + assert e.class == MyNewErrorOuter + end + end + + # DOES fail with + # - raise new(message) if exc.equal?(e) + # + raise new(message) if exc.class == e.class + def test_nested_timeout_which_error_bubbles_up + raised_exception = nil + begin + Timeout.timeout(0.1) { + Timeout.timeout(1) { + raise Timeout::ExitException.new("inner message") + } + } + rescue Exception => e + raised_exception = e + end + + assert_equal 'inner message', e.message + end + def test_cannot_convert_into_time_interval bug3168 = '[ruby-dev:41010]' def (n = Object.new).zero?; false; end