Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested exception tests for discussion #39

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions test/test_timeout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.message -> raised_exception.message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @eregon - are you saying that that is the more important thing to test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end

def test_cannot_convert_into_time_interval
bug3168 = '[ruby-dev:41010]'
def (n = Object.new).zero?; false; end
Expand Down