Class: Hydra::Runner

Inherits:
Object
  • Object
show all
Includes:
Messages::Runner
Defined in:
lib/hydra/runner.rb

Overview

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.

Constant Summary collapse

DEFAULT_LOG_FILE =
'hydra-runner.log'

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Runner

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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 } )

  $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

Instance Method Details

#format_exception(ex) ⇒ Object



88
89
90
# File 'lib/hydra/runner.rb', line 88

def format_exception(ex)
  "#{ex.class.name}: #{ex.message}\n    #{ex.backtrace.join("\n    ")}"
end

#reg_trap_sighupObject



42
43
44
45
46
47
48
49
# File 'lib/hydra/runner.rb', line 42

def reg_trap_sighup
  for sign in [:SIGHUP, :INT]
    trap sign do
      stop
    end
  end
  @runner_began = true
end

#run_file(file) ⇒ Object

Run a test file and report the results



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/hydra/runner.rb', line 57

def run_file(file)
  trace "Running file: #{file}"

  output = ""
  if file =~ /_spec.rb$/i
    output = run_rspec_file(file)
  elsif file =~ /.feature$/i
    output = run_cucumber_file(file)
  elsif file =~ /.js$/i or file =~ /.json$/i
    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_beginObject



51
52
53
54
# File 'lib/hydra/runner.rb', line 51

def runner_begin
  trace "Firing runner_begin event"
  @event_listeners.each {|l| l.runner_begin( self ) }
end

#runner_endObject



83
84
85
86
# File 'lib/hydra/runner.rb', line 83

def runner_end
  trace "Ending runner #{self.inspect}"
  @event_listeners.each {|l| l.runner_end( self ) }
end

#stopObject

Stop running



78
79
80
81
# File 'lib/hydra/runner.rb', line 78

def stop
  runner_end if @runner_began
  @runner_began = @running = false
end