class Hydra::Runner

Hydra class responsible for running test files.

The Runner is never run directly by a user. Runners are created by a Worker to run test files.

The general convention is to have one Runner for each logical processor of a machine.

Constants

DEFAULT_LOG_FILE

Public Class Methods

new(opts = {}) click to toggle source

Boot up a runner. It takes an IO object (generally a pipe from its parent) to send it messages on which files to execute.

# File lib/hydra/runner.rb, line 21
def initialize(opts = {})
  redirect_output( opts.fetch( :runner_log_file ) { DEFAULT_LOG_FILE } )
  reg_trap_sighup

  @io = opts.fetch(:io) { raise "No IO Object" }
  @verbose = opts.fetch(:verbose) { false }
  @event_listeners = Array( opts.fetch( :runner_listeners ) { nil } )
  @options = opts.fetch(:options) { "" }
  @directory = get_directory

  $stdout.sync = true
  runner_begin

  trace 'Booted. Sending Request for file'
  @io.write RequestFile.new
  begin
    process_messages
  rescue => ex
    trace ex.to_s
    raise ex
  end
end

Public Instance Methods

format_exception(ex) click to toggle source
# File lib/hydra/runner.rb, line 90
def format_exception(ex)
  "#{ex.class.name}: #{ex.message}\n    #{ex.backtrace.join("\n    ")}"
end
reg_trap_sighup() click to toggle source
# File lib/hydra/runner.rb, line 44
def reg_trap_sighup
  for sign in [:SIGHUP, :INT]
    trap sign do
      stop
    end
  end
  @runner_began = true
end
run_file(file) click to toggle source

Run a test file and report the results

# File lib/hydra/runner.rb, line 59
def run_file(file)
  trace "Running file: #{file}"

  output = ""
  if file =~ %r_spec.rb$/
    output = run_rspec_file(file)
  elsif file =~ %r.feature$/
    output = run_cucumber_file(file)
  elsif file =~ %r.js$/ or file =~ %r.json$/
    output = run_javascript_file(file)
  else
    output = run_test_unit_file(file)
  end

  output = "." if output == ""

  @io.write Results.new(:output => output, :file => file)
  return output
end
runner_begin() click to toggle source
# File lib/hydra/runner.rb, line 53
def runner_begin
  trace "Firing runner_begin event"
  @event_listeners.each {|l| l.runner_begin( self ) }
end
runner_end() click to toggle source
# File lib/hydra/runner.rb, line 85
def runner_end
  trace "Ending runner #{self.inspect}"
  @event_listeners.each {|l| l.runner_end( self ) }
end
stop() click to toggle source

Stop running

# File lib/hydra/runner.rb, line 80
def stop
  runner_end if @runner_began
  @runner_began = @running = false
end