File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -177,6 +177,33 @@ def connect *args
177
177
} . should raise_error ( Mysql2 ::Error )
178
178
end
179
179
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
+
180
207
it "threaded queries should be supported" do
181
208
threads , results = [ ] , { }
182
209
connect = lambda { Mysql2 ::Client . new ( :host => "localhost" , :username => "root" ) }
You can’t perform that action at this time.
0 commit comments