Class: Loupe::ProcessExecutor

Inherits:
Executor
  • Object
show all
Defined in:
lib/loupe/process_executor.rb

Overview

ProcessExecutor

This class is responsible for executing tests in process mode.

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Loupe::Executor

Create a new ProcessExecutor

This will create a new server object that will be shared with child processes using DRb

Parameters:

  • options (Hash<Symbol, BasicObject>)


16
17
18
19
20
21
# File 'lib/loupe/process_executor.rb', line 16

def initialize(options)
  super

  @server = QueueServer.new(populate_queue, @reporter)
  @url = DRb.start_service("drbunix:", @server).uri
end

Instance Method Details

#runInteger

run

Fork each one of the process workers and connect with the server object coming from DRb. Run until the queue is clear

Returns:

  • (Integer)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/loupe/process_executor.rb', line 28

def run
  @workers = (0...[Etc.nprocessors, @server.length].min).map do
    fork do
      DRb.start_service
      server = DRbObject.new_with_uri(@url)

      until server.empty?
        klass, method_name = server.pop
        server.add_reporter(klass.run(method_name, @options)) if klass && method_name
      end
    end
  end

  shutdown
  @reporter.print_summary
  @reporter.exit_status
end