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
41
42
# 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

Instance Method Details

#format_exception(ex) ⇒ Object



90
91
92
# File 'lib/hydra/runner.rb', line 90

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

#reg_trap_sighupObject



44
45
46
47
48
49
50
51
# 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) ⇒ Object

Run a test file and report the results



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

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



53
54
55
56
# 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_endObject



85
86
87
88
# File 'lib/hydra/runner.rb', line 85

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

#stopObject

Stop running



80
81
82
83
# File 'lib/hydra/runner.rb', line 80

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