Skip to content

Commit dd8d99c

Browse files
committed
Merge pull request #180 from loe/0.2.x
0.2.x test for issue #99
2 parents 4e84430 + bf6bccd commit dd8d99c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

spec/mysql2/client_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,33 @@ def connect *args
177177
}.should raise_error(Mysql2::Error)
178178
end
179179

180+
it "should close the connection when an exception is raised" do
181+
begin
182+
Timeout.timeout(1) do
183+
@client.query("SELECT sleep(2)")
184+
end
185+
rescue Timeout::Error
186+
end
187+
188+
lambda {
189+
@client.query("SELECT 1")
190+
}.should raise_error(Mysql2::Error, 'closed MySQL connection')
191+
end
192+
193+
it "should handle Timeouts without leaving the connection hanging if reconnect is true" do
194+
client = Mysql2::Client.new(:reconnect => true)
195+
begin
196+
Timeout.timeout(1) do
197+
client.query("SELECT sleep(2)")
198+
end
199+
rescue Timeout::Error
200+
end
201+
202+
lambda {
203+
client.query("SELECT 1")
204+
}.should_not raise_error(Mysql2::Error)
205+
end
206+
180207
it "threaded queries should be supported" do
181208
threads, results = [], {}
182209
connect = lambda{ Mysql2::Client.new(:host => "localhost", :username => "root") }

0 commit comments

Comments
 (0)