123456789_123456789_123456789_123456789_123456789_

Class: Minitest::Parallel::Executor

Relationships & Source Files
Inherits: Object
Defined in: lib/minitest/parallel.rb

Overview

The engine used to run multiple tests in parallel.

Class Method Summary

Instance Attribute Summary

  • #size readonly

    The size of the pool of workers.

Instance Method Summary

  • #<<(work)

    Add a job to the queue.

  • #shutdown

    Shuts down the pool of workers by signalling them to quit and waiting for them all to finish what they're currently working on.

  • #start

    Start the executor.

Constructor Details

.new(size) ⇒ Executor

Create a parallel test executor of with #size workers.

[ GitHub ]

  
# File 'lib/minitest/parallel.rb', line 17

def initialize size
  @size  = size
  @queue = Queue.new
  @pool  = nil
end

Instance Attribute Details

#size (readonly)

The size of the pool of workers.

[ GitHub ]

  
# File 'lib/minitest/parallel.rb', line 12

attr_reader :size

Instance Method Details

#<<(work)

Add a job to the queue

[ GitHub ]

  
# File 'lib/minitest/parallel.rb', line 43

def << work; @queue << work; end

#shutdown

Shuts down the pool of workers by signalling them to quit and waiting for them all to finish what they're currently working on.

[ GitHub ]

  
# File 'lib/minitest/parallel.rb', line 50

def shutdown
  size.times { @queue << nil }
  @pool.each(&:join)
end

#start

Start the executor

[ GitHub ]

  
# File 'lib/minitest/parallel.rb', line 26

def start
  @pool  = size.times.map {
    Thread.new(@queue) do |queue|
      Thread.current.abort_on_exception = true
      while (job = queue.pop)
        klass, method, reporter = job
        reporter.synchronize { reporter.prerecord klass, method }
        result = Minitest.run_one_method klass, method
        reporter.synchronize { reporter.record result }
      end
    end
  }
end