Class: Loupe::RactorExecutor
- Defined in:
- lib/loupe/ractor_executor.rb
Overview
RactorExecutor
This class is responsible for the execution flow. It populates the queue of tests to be executed, instantiates the workers, creates an accumulator reporter and delegates tests to workers until the queue is empty.
Instance Method Summary collapse
- #initialize(options) ⇒ Loupe::Executor constructor
-
#run ⇒ Integer
Run the main process for executing tests.
Constructor Details
#initialize(options) ⇒ Loupe::Executor
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/loupe/ractor_executor.rb', line 13 def initialize() super @workers = (0...[Etc.nprocessors, @queue.length].min).map do Ractor.new() do |opts| loop do klass, method_name = Ractor.receive Ractor.yield klass.run(method_name, opts) end end end end |
Instance Method Details
#run ⇒ Integer
Run the main process for executing tests
Send the first tests to all workers from the queue and then keep selecting the idle Ractor until the queue is empty. Acumulate the reporters as tests are finalized. The last set of results are obtained outside the loop using ‘take`, since once the queue is empty `select` will no longer accumulate the result.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/loupe/ractor_executor.rb', line 34 def run @workers.each do |r| item = @queue.pop r.send(item) unless item.nil? end until @queue.empty? idle_worker, tmp_reporter = Ractor.select(*@workers) @reporter << tmp_reporter idle_worker.send(@queue.pop) end @workers.each { |w| @reporter << w.take } @reporter.print_summary @reporter.exit_status end |