Sha256: 31af4f48dffb19c66befb05b267b5fb3a1a2881e351f33ba1450ea3f0b1771e8
Contents?: true
Size: 1.05 KB
Versions: 10
Compression:
Stored size: 1.05 KB
Contents
require 'test_helper' class Workhorse::PoolTest < WorkhorseTest def test_idle with_pool 5 do |p| assert_equal 5, p.idle 4.times do |_i| p.post do sleep 0.2 end end sleep 0.1 assert_equal 1, p.idle sleep 0.2 assert_equal 5, p.idle end end def test_overflow with_pool 5 do |p| 5.times { p.post { sleep 0.2 } } exception = assert_raises do p.post { sleep 1 } end assert_equal 'All threads are busy.', exception.message end end def test_work with_pool 5 do |p| counter = Concurrent::AtomicFixnum.new(0) 5.times do p.post do counter.increment end end sleep 0.01 assert_equal 5, counter.value 2.times do p.post do counter.increment end end sleep 0.01 assert_equal 7, counter.value end end private def with_pool(size) p = Workhorse::Pool.new(size) begin yield(p) ensure p.shutdown end end end
Version data entries
10 entries across 10 versions & 1 rubygems