mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
rename start to run and use Thread.pass rather than sleeping to schedule the watchdog
This commit is contained in:
parent
405aeb5da4
commit
59f2696d00
2 changed files with 30 additions and 22 deletions
|
@ -75,7 +75,7 @@ module ActiveRecord
|
||||||
@frequency = frequency
|
@frequency = frequency
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def run
|
||||||
return unless frequency
|
return unless frequency
|
||||||
Thread.new(frequency, pool) { |t, p|
|
Thread.new(frequency, pool) { |t, p|
|
||||||
while true
|
while true
|
||||||
|
@ -107,7 +107,7 @@ module ActiveRecord
|
||||||
|
|
||||||
@timeout = spec.config[:wait_timeout] || 5
|
@timeout = spec.config[:wait_timeout] || 5
|
||||||
@reaper = Reaper.new self, spec.config[:reaping_frequency]
|
@reaper = Reaper.new self, spec.config[:reaping_frequency]
|
||||||
@reaper.start
|
@reaper.run
|
||||||
|
|
||||||
# default max pool size to 5
|
# default max pool size to 5
|
||||||
@size = (spec.config[:pool] && spec.config[:pool].to_i) || 5
|
@size = (spec.config[:pool] && spec.config[:pool].to_i) || 5
|
||||||
|
|
|
@ -15,31 +15,37 @@ module ActiveRecord
|
||||||
@pool.connections.each(&:close)
|
@pool.connections.each(&:close)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class FakePool
|
||||||
|
attr_reader :reaped
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@reaped = false
|
||||||
|
end
|
||||||
|
|
||||||
|
def reap
|
||||||
|
@reaped = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# A reaper with nil time should never reap connections
|
# A reaper with nil time should never reap connections
|
||||||
def test_nil_time
|
def test_nil_time
|
||||||
conn = pool.checkout
|
fp = FakePool.new
|
||||||
pool.timeout = 0
|
assert !fp.reaped
|
||||||
|
reaper = ConnectionPool::Reaper.new(fp, nil)
|
||||||
count = pool.connections.length
|
reaper.run
|
||||||
conn.extend(Module.new { def active?; false; end; })
|
assert !fp.reaped
|
||||||
|
|
||||||
reaper = ConnectionPool::Reaper.new(pool, nil)
|
|
||||||
reaper.start
|
|
||||||
sleep 0.0001
|
|
||||||
assert_equal count, pool.connections.length
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_some_time
|
def test_some_time
|
||||||
conn = pool.checkout
|
fp = FakePool.new
|
||||||
pool.timeout = 0
|
assert !fp.reaped
|
||||||
|
|
||||||
count = pool.connections.length
|
reaper = ConnectionPool::Reaper.new(fp, 0.0001)
|
||||||
conn.extend(Module.new { def active?; false; end; })
|
reaper.run
|
||||||
|
until fp.reaped
|
||||||
reaper = ConnectionPool::Reaper.new(pool, 0.0001)
|
Thread.pass
|
||||||
reaper.start
|
end
|
||||||
sleep 0.0002
|
assert fp.reaped
|
||||||
assert_equal(count - 1, pool.connections.length)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_pool_has_reaper
|
def test_pool_has_reaper
|
||||||
|
@ -65,7 +71,9 @@ module ActiveRecord
|
||||||
|
|
||||||
conn.extend(Module.new { def active?; false; end; })
|
conn.extend(Module.new { def active?; false; end; })
|
||||||
|
|
||||||
sleep 0.0002
|
while count == pool.connections.length
|
||||||
|
Thread.pass
|
||||||
|
end
|
||||||
assert_equal(count - 1, pool.connections.length)
|
assert_equal(count - 1, pool.connections.length)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue