@@ -342,6 +342,19 @@ def run_gc
342
342
@client . close
343
343
expect ( @client . closed? ) . to eql ( true )
344
344
end
345
+
346
+ it "should detect a closed connection" do
347
+ connection_id = @client . thread_id
348
+ Thread . new do
349
+ sleep ( 0.1 )
350
+ Mysql2 ::Client . new ( DatabaseCredentials [ 'root' ] ) . tap do |supervisor |
351
+ supervisor . query ( "KILL #{ connection_id } " )
352
+ end . close
353
+ end
354
+ expect ( @client . query ( "SELECT 1" ) . first [ "1" ] ) . to eql ( 1 )
355
+ sleep ( 0.2 )
356
+ expect ( @client . closed? ) . to be true
357
+ end
345
358
end
346
359
347
360
it "should not try to query closed mysql connection" do
@@ -573,7 +586,7 @@ def run_gc
573
586
end
574
587
expect do
575
588
@client . query ( "SELECT SLEEP(1)" )
576
- end . to raise_error ( Mysql2 ::Error , /Lost connection to MySQL server/ )
589
+ end . to raise_error ( Mysql2 ::Error , 'MySQL client is not connected' )
577
590
578
591
if RUBY_PLATFORM !~ /mingw|mswin/
579
592
expect do
@@ -582,6 +595,19 @@ def run_gc
582
595
end
583
596
end
584
597
598
+ it "should detect a closed connection" do
599
+ connection_id = @client . thread_id
600
+ Thread . new do
601
+ sleep ( 0.1 )
602
+ Mysql2 ::Client . new ( DatabaseCredentials [ 'root' ] ) . tap do |supervisor |
603
+ supervisor . query ( "KILL #{ connection_id } " )
604
+ end . close
605
+ end
606
+ expect ( @client . query ( "SELECT 1" ) . first [ "1" ] ) . to eql ( 1 )
607
+ sleep ( 0.2 )
608
+ expect ( @client . closed? ) . to be true
609
+ end
610
+
585
611
if RUBY_PLATFORM !~ /mingw|mswin/
586
612
it "should not allow another query to be sent without fetching a result first" do
587
613
@client . query ( "SELECT 1" , async : true )
0 commit comments