Skip to content

Commit 17d5cfc

Browse files
committed
Spec for should not leaving dangling connections
1 parent c514179 commit 17d5cfc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

spec/mysql2/client_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ def connect *args
104104
ssl_client.close
105105
end
106106

107+
it "should not leave dangling connections after garbage collection" do
108+
GC.start
109+
client = Mysql2::Client.new(DatabaseCredentials['root'])
110+
before_count = client.query("SHOW STATUS LIKE 'Threads_connected'").first['Value'].to_i
111+
112+
10.times do
113+
Mysql2::Client.new(DatabaseCredentials['root']).query('SELECT 1')
114+
end
115+
after_count = client.query("SHOW STATUS LIKE 'Threads_connected'").first['Value'].to_i
116+
after_count.should == before_count + 10
117+
118+
GC.start
119+
final_count = client.query("SHOW STATUS LIKE 'Threads_connected'").first['Value'].to_i
120+
final_count.should == before_count
121+
end
122+
107123
it "should be able to connect to database with numeric-only name" do
108124
lambda {
109125
creds = DatabaseCredentials['numericuser']

0 commit comments

Comments
 (0)