diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-30 16:10:53 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-30 16:10:53 -0800 |
commit | 59f2696d0012c451190a9e3fe1b92c3619dee1a2 (patch) | |
tree | 431909c726fca4537f17ab762a27942b5dae2fe1 /activerecord/test/cases | |
parent | 405aeb5da4eea3b9defdea2ce0920725dcd75308 (diff) | |
download | rails-59f2696d0012c451190a9e3fe1b92c3619dee1a2.tar.gz rails-59f2696d0012c451190a9e3fe1b92c3619dee1a2.tar.bz2 rails-59f2696d0012c451190a9e3fe1b92c3619dee1a2.zip |
rename start to run and use Thread.pass rather than sleeping to schedule the watchdog
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/reaper_test.rb | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/activerecord/test/cases/reaper_test.rb b/activerecord/test/cases/reaper_test.rb index 9149d45e7c..576ab60090 100644 --- a/activerecord/test/cases/reaper_test.rb +++ b/activerecord/test/cases/reaper_test.rb @@ -15,31 +15,37 @@ module ActiveRecord @pool.connections.each(&:close) end - # A reaper with nil time should never reap connections - def test_nil_time - conn = pool.checkout - pool.timeout = 0 + class FakePool + attr_reader :reaped - count = pool.connections.length - conn.extend(Module.new { def active?; false; end; }) + def initialize + @reaped = false + end - reaper = ConnectionPool::Reaper.new(pool, nil) - reaper.start - sleep 0.0001 - assert_equal count, pool.connections.length + def reap + @reaped = true + end end - def test_some_time - conn = pool.checkout - pool.timeout = 0 - - count = pool.connections.length - conn.extend(Module.new { def active?; false; end; }) + # A reaper with nil time should never reap connections + def test_nil_time + fp = FakePool.new + assert !fp.reaped + reaper = ConnectionPool::Reaper.new(fp, nil) + reaper.run + assert !fp.reaped + end - reaper = ConnectionPool::Reaper.new(pool, 0.0001) - reaper.start - sleep 0.0002 - assert_equal(count - 1, pool.connections.length) + def test_some_time + fp = FakePool.new + assert !fp.reaped + + reaper = ConnectionPool::Reaper.new(fp, 0.0001) + reaper.run + until fp.reaped + Thread.pass + end + assert fp.reaped end def test_pool_has_reaper @@ -65,7 +71,9 @@ module ActiveRecord 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) end end |