Skip to content

Commit

Permalink
Update specs for Ruby 2.1 Timeout behavior by specifying 'Timeout::Er…
Browse files Browse the repository at this point in the history
…ror' as the klass parameter.

With thanks to @bpardee: "if you look at the difference between 2.0 doc and 2.1
doc, it specifically adds the following to the description: The exception thrown
to terminate the given block cannot be rescued inside the block unless klass is
given explicitly."
  • Loading branch information
sodabrew committed Apr 21, 2014
1 parent 716eacf commit d0a5199
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions spec/mysql2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def connect *args
end

it "should send init_command after reconnect" do
pending "Ruby 2.1 has changed Timeout behavior." if RUBY_VERSION =~ /2.1/
options = DatabaseCredentials['root'].dup
options[:init_command] = "SET @something = 'setting_value';"
options[:reconnect] = true
Expand All @@ -94,7 +93,7 @@ def connect *args

# simulate a broken connection
begin
Timeout.timeout(1) do
Timeout.timeout(1, Timeout::Error) do
client.query("SELECT sleep(2)")
end
rescue Timeout::Error
Expand Down Expand Up @@ -449,9 +448,8 @@ def connect *args
end

it "should close the connection when an exception is raised" do
pending "Ruby 2.1 has changed Timeout behavior." if RUBY_VERSION =~ /2.1/
begin
Timeout.timeout(1) do
Timeout.timeout(1, Timeout::Error) do
@client.query("SELECT sleep(2)")
end
rescue Timeout::Error
Expand All @@ -463,10 +461,9 @@ def connect *args
end

it "should handle Timeouts without leaving the connection hanging if reconnect is true" do
pending "Ruby 2.1 has changed Timeout behavior." if RUBY_VERSION =~ /2.1/
client = Mysql2::Client.new(DatabaseCredentials['root'].merge(:reconnect => true))
begin
Timeout.timeout(1) do
Timeout.timeout(1, Timeout::Error) do
client.query("SELECT sleep(2)")
end
rescue Timeout::Error
Expand All @@ -478,10 +475,9 @@ def connect *args
end

it "should handle Timeouts without leaving the connection hanging if reconnect is set to true after construction true" do
pending "Ruby 2.1 has changed Timeout behavior." if RUBY_VERSION =~ /2.1/
client = Mysql2::Client.new(DatabaseCredentials['root'])
begin
Timeout.timeout(1) do
Timeout.timeout(1, Timeout::Error) do
client.query("SELECT sleep(2)")
end
rescue Timeout::Error
Expand All @@ -494,7 +490,7 @@ def connect *args
client.reconnect = true

begin
Timeout.timeout(1) do
Timeout.timeout(1, Timeout::Error) do
client.query("SELECT sleep(2)")
end
rescue Timeout::Error
Expand Down

0 comments on commit d0a5199

Please sign in to comment.