Class: ActiveSupport::Testing::Parallelization::ThreadPoolExecutor
- Defined in:
- activesupport/lib/active_support/testing/parallelization/thread_pool_executor.rb
Overview
Thread pool executor using a test distributor strategy. Provides the same interface as Minitest::Parallel::Executor but with configurable distribution (round robin vs work stealing).
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #<<(work) ⇒ Object
-
#initialize(size:, distributor:) ⇒ ThreadPoolExecutor
constructor
A new instance of ThreadPoolExecutor.
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(size:, distributor:) ⇒ ThreadPoolExecutor
Returns a new instance of ThreadPoolExecutor.
14 15 16 17 18 |
# File 'activesupport/lib/active_support/testing/parallelization/thread_pool_executor.rb', line 14 def initialize(size:, distributor:) @size = size @distributor = distributor @pool = Concurrent::FixedThreadPool.new(size, fallback_policy: :abort) end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
12 13 14 |
# File 'activesupport/lib/active_support/testing/parallelization/thread_pool_executor.rb', line 12 def size @size end |
Instance Method Details
#<<(work) ⇒ Object
26 27 28 |
# File 'activesupport/lib/active_support/testing/parallelization/thread_pool_executor.rb', line 26 def <<(work) @distributor.add_test(work) end |
#shutdown ⇒ Object
30 31 32 33 34 |
# File 'activesupport/lib/active_support/testing/parallelization/thread_pool_executor.rb', line 30 def shutdown @distributor.close @pool.shutdown @pool.wait_for_termination end |
#start ⇒ Object
20 21 22 23 24 |
# File 'activesupport/lib/active_support/testing/parallelization/thread_pool_executor.rb', line 20 def start size.times do |worker_id| @pool.post { worker_loop(worker_id) } end end |