Sha256: bd35f020926902d0a581dc027651696cfb2467a35fb01cfd3c75d87f1dc505e7
Contents?: true
Size: 1.42 KB
Versions: 1
Compression:
Stored size: 1.42 KB
Contents
# frozen_string_literal: true require_relative 'helper' class ThreadPoolTest < MiniTest::Test def setup super @pool = Polyphony::ThreadPool.new end def test_process current_thread = Thread.current processing_thread = nil result = @pool.process do processing_thread = Thread.current +'foo' + 'bar' end assert_equal 'foobar', result assert processing_thread != current_thread end def test_multi_process current_thread = Thread.current threads = [] results = [] 10.times do |i| spin do results << @pool.process do threads << Thread.current sleep 0.01 i * 10 end end end suspend assert_equal @pool.size, threads.uniq.size assert_equal (0..9).map { |i| i * 10}, results.sort end def test_process_with_exception result = nil begin result = @pool.process { raise 'foo' } rescue => result end assert_kind_of RuntimeError, result assert_equal 'foo', result.message end def test_cast t0 = Time.now threads = [] buffer = [] 10.times do |i| @pool.cast do sleep 0.01 threads << Thread.current buffer << i end end elapsed = Time.now - t0 assert elapsed < 0.005 assert buffer.size < 2 sleep 0.04 assert_equal @pool.size, threads.uniq.size assert_equal (0..9).to_a, buffer.sort end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
polyphony-0.28 | test/test_thread_pool.rb |