Class: Hydra::Master

Inherits:
Object
  • Object
show all
Includes:
Hydra::Messages::Master
Defined in:
lib/hydra/master.rb

Overview

Hydra class responsible for delegate work down to workers.

The Master is run once for any given testing session.

Instance Method Summary collapse

Constructor Details

#initialize(opts = { }) ⇒ Master

Create a new Master

Options:

  • :files

    • An array of test files to be run. These should be relative paths from the root of the project, since they may be run on different machines which may have different paths.

  • :workers

    • An array of hashes. Each hash should be the configuration options for a worker.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/hydra/master.rb', line 19

def initialize(opts = { })
  opts.stringify_keys!
  config_file = opts.delete('config') { nil }
  if config_file
    opts.merge!(YAML.load_file(config_file).stringify_keys!)
  end
  @files = opts.fetch('files') { [] }
  @files.sort!{|a,b| File.size(b) <=> File.size(a)} # dumb heuristic
  @incomplete_files = @files.dup
  @workers = []
  @listeners = []
  @verbose = opts.fetch('verbose') { false }
  # default is one worker that is configured to use a pipe with one runner
  worker_cfg = opts.fetch('workers') { [ { 'type' => 'local', 'runners' => 1} ] }

  trace "Initialized"
  trace "  Files:   (#{@files.inspect})"
  trace "  Workers: (#{worker_cfg.inspect})"
  trace "  Verbose: (#{@verbose.inspect})"

  boot_workers worker_cfg
  process_messages
end

Instance Method Details

#process_results(worker, message) ⇒ Object

Process the results coming back from the worker.



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/hydra/master.rb', line 53

def process_results(worker, message)
  $stdout.write message.output
  # only delete one
  @incomplete_files.delete_at(@incomplete_files.index(message.file))
  trace "#{@incomplete_files.size} Files Remaining"
  if @incomplete_files.empty?
    shutdown_all_workers
  else
    send_file(worker)
  end
end

#send_file(worker) ⇒ Object

Send a file down to a worker. If there are no more files, this will shut the worker down.



47
48
49
50
# File 'lib/hydra/master.rb', line 47

def send_file(worker)
  f = @files.pop
  worker[:io].write(RunFile.new(:file => f)) if f
end