diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-30 15:19:07 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-30 15:19:07 -0800 |
commit | cde7692d4e3e0e67e480cc6172f6e2bacaceeb5e (patch) | |
tree | 8b31ee31bee1cebc067174fc7355ea1f0b503708 /activerecord/test | |
parent | cceabe03a80c4a0121a2b1187b56a2d29586a43b (diff) | |
download | rails-cde7692d4e3e0e67e480cc6172f6e2bacaceeb5e.tar.gz rails-cde7692d4e3e0e67e480cc6172f6e2bacaceeb5e.tar.bz2 rails-cde7692d4e3e0e67e480cc6172f6e2bacaceeb5e.zip |
introduce a timer class for reaping connections
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/reaper_test.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/activerecord/test/cases/reaper_test.rb b/activerecord/test/cases/reaper_test.rb new file mode 100644 index 0000000000..ed3daa175d --- /dev/null +++ b/activerecord/test/cases/reaper_test.rb @@ -0,0 +1,46 @@ +require "cases/helper" + +module ActiveRecord + module ConnectionAdapters + class ReaperTest < ActiveRecord::TestCase + attr_reader :pool + + def setup + super + @pool = ConnectionPool.new ActiveRecord::Base.connection_pool.spec + end + + def teardown + super + @pool.connections.each(&:close) + end + + # A reaper with nil time should never reap connections + def test_nil_time + conn = pool.checkout + pool.timeout = 0 + + count = pool.connections.length + conn.extend(Module.new { def active?; false; end; }) + + reaper = ConnectionPool::Reaper.new(pool, nil) + reaper.start + sleep 0.0001 + assert_equal count, pool.connections.length + end + + def test_some_time + conn = pool.checkout + pool.timeout = 0 + + count = pool.connections.length + conn.extend(Module.new { def active?; false; end; }) + + reaper = ConnectionPool::Reaper.new(pool, 0.0001) + reaper.start + sleep 0.0002 + assert_equal(count - 1, pool.connections.length) + end + end + end +end |