Class: ActiveSupport::Testing::Parallelization::ThreadPoolExecutor

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#sizeObject (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

#shutdownObject



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

#startObject



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