Class: JCukeForker::Runner

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/jcukeforker/runner.rb

Overview

Runner.run(features, opts)

where ‘features’ is an Array of file:line and ‘opts’ is a Hash of options:

:max        => Fixnum            number of workers (default: 2, pass 0 for unlimited)
:vnc        => true/false,Class,Array  children are launched with DISPLAY set from a VNC server pool,
                                 where the size of the pool is equal to :max. If passed a Class instance,
                                 this will be passed as the second argument to VncTools::ServerPool.
:record     => true/false,Hash   whether to record a video of failed tests (requires ffmpeg)
                                 this will be ignored if if :vnc is not true. If passed a Hash,
                                 this will be passed as options to RecordingVncListener
:notify     => object            (or array of objects) implementing the AbstractListener API
:out        => path              directory to dump output to (default: current working dir)
:log        => true/false        wether or not to log to stdout (default: true)
:format     => Symbol            format passed to `cucumber --format` (default: html)
:extra_args => Array             extra arguments passed to cucumber
:delay      => Numeric           seconds to sleep between each worker is started (default: 0)

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :max    => 2,
  :vnc    => false,
  :record => false,
  :notify => nil,
  :out    => Dir.pwd,
  :log    => true,
  :format => :html,
  :delay  => 0
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_server, processes, worker_dir, vnc_pool, delay) ⇒ Runner

Returns a new instance of Runner.



89
90
91
92
93
94
95
# File 'lib/jcukeforker/runner.rb', line 89

def initialize(status_server, processes, worker_dir, vnc_pool, delay)
  @status_server = status_server
  @processes = processes
  @worker_dir = worker_dir
  @vnc_pool = vnc_pool
  @delay = delay
end

Class Method Details

.create(features, opts = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/jcukeforker/runner.rb', line 42

def self.create(features, opts = {})
  opts = DEFAULT_OPTIONS.dup.merge(opts)

  max        = opts[:max]
  format     = opts[:format]
  out        = File.join opts[:out]
  listeners  = Array(opts[:notify])
  extra_args = Array(opts[:extra_args])
  delay      = opts[:delay]

  if opts[:log]
    listeners << LoggingListener.new
  end

  task_manager = TaskManager.new
  features.each do |feature|
    task_manager.add({feature: feature, format: format,out: out,extra_args: extra_args})
  end

  listeners << task_manager
  status_server = StatusServer.new '6333'
  worker_dir = "/tmp/jcukeforker-#{SecureRandom.hex 4}"
  FileUtils.mkdir_p worker_dir

  vnc_pool = nil
  if vnc = opts[:vnc]
   if vnc.kind_of?(Array)
     vnc_pool = VncTools::ServerPool.new(max, ConfigurableVncServer.create_class(vnc))
   elsif vnc.kind_of?(Class)
     vnc_pool = VncTools::ServerPool.new(max, vnc)
   else
     vnc_pool = VncTools::ServerPool.new(max)
   end
  end

  processes = create_processes(max, '6333', worker_dir, vnc_pool, opts[:record])

  runner = Runner.new status_server, processes, worker_dir, vnc_pool, delay

  listeners.each { |l|
    status_server.add_observer l
    runner.add_observer l
  }

  runner
end

.run(features, opts = {}) ⇒ Object



38
39
40
# File 'lib/jcukeforker/runner.rb', line 38

def self.run(features, opts = {})
  create(features, opts).run
end

Instance Method Details

#runObject



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/jcukeforker/runner.rb', line 97

def run
  start
  process
  stop
rescue Interrupt
  fire :on_run_interrupted
  stop
rescue StandardError
  fire :on_run_interrupted
  stop
  raise
end