@@ -342,6 +342,19 @@ def run_gc
342342 @client . close
343343 expect ( @client . closed? ) . to eql ( true )
344344 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
345358 end
346359
347360 it "should not try to query closed mysql connection" do
@@ -573,7 +586,7 @@ def run_gc
573586 end
574587 expect do
575588 @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' )
577590
578591 if RUBY_PLATFORM !~ /mingw|mswin/
579592 expect do
@@ -582,6 +595,19 @@ def run_gc
582595 end
583596 end
584597
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+
585611 if RUBY_PLATFORM !~ /mingw|mswin/
586612 it "should not allow another query to be sent without fetching a result first" do
587613 @client . query ( "SELECT 1" , async : true )
0 commit comments