Skip to content

Commit 3184108

Browse files
committed
DRY
1 parent e5b05a9 commit 3184108

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

spec/mysql2/client_spec.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,14 @@ def connect *args
149149
ssl_client.close
150150
end
151151

152-
it "should not leave dangling connections after garbage collection" do
152+
def run_gc
153153
GC.start
154-
sleep 0.300 # Let GC do its work
154+
sleep(1) if defined?(Rubinius) # Let the Rubinius GC thread do its work
155+
end
156+
157+
it "should not leave dangling connections after garbage collection" do
158+
run_gc
159+
155160
client = Mysql2::Client.new(DatabaseCredentials['root'])
156161
before_count = client.query("SHOW STATUS LIKE 'Threads_connected'").first['Value'].to_i
157162

@@ -161,23 +166,20 @@ def connect *args
161166
after_count = client.query("SHOW STATUS LIKE 'Threads_connected'").first['Value'].to_i
162167
after_count.should == before_count + 10
163168

164-
GC.start
165-
sleep 0.300 # Let GC do its work
169+
run_gc
166170
final_count = client.query("SHOW STATUS LIKE 'Threads_connected'").first['Value'].to_i
167171
final_count.should == before_count
168172
end
169173

170174
if Process.respond_to?(:fork)
171175
it "should not close connections when running in a child process" do
172-
GC.start
173-
sleep 1 if defined? Rubinius # Let the rbx GC thread do its work
176+
run_gc
174177
client = Mysql2::Client.new(DatabaseCredentials['root'])
175178

176179
fork do
177180
client.query('SELECT 1')
178181
client = nil
179-
GC.start
180-
sleep 1 if defined? Rubinius # Let the rbx GC thread do its work
182+
run_gc
181183
end
182184

183185
Process.wait

0 commit comments

Comments
 (0)