Skip to content

Commit d0a5199

Browse files
committed
Update specs for Ruby 2.1 Timeout behavior by specifying 'Timeout::Error' 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."
1 parent 716eacf commit d0a5199

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

spec/mysql2/client_spec.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def connect *args
8383
end
8484

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

9594
# simulate a broken connection
9695
begin
97-
Timeout.timeout(1) do
96+
Timeout.timeout(1, Timeout::Error) do
9897
client.query("SELECT sleep(2)")
9998
end
10099
rescue Timeout::Error
@@ -449,9 +448,8 @@ def connect *args
449448
end
450449

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

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

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

496492
begin
497-
Timeout.timeout(1) do
493+
Timeout.timeout(1, Timeout::Error) do
498494
client.query("SELECT sleep(2)")
499495
end
500496
rescue Timeout::Error

0 commit comments

Comments
 (0)