Class: Megatest::MultiProcess::Executor

Inherits:
AbstractExecutor show all
Defined in:
lib/megatest/multi_process.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, managed: false) ⇒ Executor

Returns a new instance of Executor.



209
210
211
212
# File 'lib/megatest/multi_process.rb', line 209

def initialize(*args, managed: false)
  super(*args)
  @managed = managed
end

Instance Attribute Details

#wall_timeObject (readonly)

Returns the value of attribute wall_time.



207
208
209
# File 'lib/megatest/multi_process.rb', line 207

def wall_time
  @wall_time
end

Instance Method Details

#after_fork_in_child(active_job) ⇒ Object



218
219
220
221
222
# File 'lib/megatest/multi_process.rb', line 218

def after_fork_in_child(active_job)
  @jobs.each do |job|
    job.close unless job == active_job
  end
end

#concurrent?Boolean

Returns:

  • (Boolean)


214
215
216
# File 'lib/megatest/multi_process.rb', line 214

def concurrent?
  true
end

#run(queue, reporters) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/megatest/multi_process.rb', line 224

def run(queue, reporters)
  start_time = Megatest.now
  @config.run_global_setup_callbacks
  reporters.each { |r| r.start(self, queue) }
  @jobs = @config.jobs_count.times.map { |index| Job.new(@config, index) }

  @config.before_fork_callbacks.each(&:call)
  @jobs.each { |j| j.run(self, queue.test_cases_index) }

  monitor = InlineMonitor.new(@config, queue) if queue.respond_to?(:heartbeat)

  begin
    while true
      monitor&.tick
      dead_jobs = @jobs.select(&:closed?).each { |j| j.on_exit(queue, reporters) }
      @jobs -= dead_jobs
      break if @jobs.empty?
      break if queue.empty?

      @jobs.select(&:idle?).each do |job|
        job.process(queue, reporters)
      end

      reads, = IO.select(@jobs, nil, nil, 1)
      reads&.each do |job|
        job.process(queue, reporters)
      end

      break if @config.circuit_breaker.break?
    end
  rescue Interrupt
    @jobs.each(&:term) # Early exit
  end

  @jobs.each(&:close)
  @jobs.each(&:reap)
  @wall_time = Megatest.now - start_time
  reporters.each { |r| r.summary(self, queue, queue.summary) }

  if @config.circuit_breaker.break? && !@managed
    @out.error("Exited early because too many failures were encountered")
  end

  queue.cleanup
end