Class: Megatest::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/megatest/executor.rb

Defined Under Namespace

Classes: ExternalMonitor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, out) ⇒ Executor

Returns a new instance of Executor.



51
52
53
54
# File 'lib/megatest/executor.rb', line 51

def initialize(config, out)
  @config = config
  @out = Output.new(out, colors: @config.colors)
end

Instance Attribute Details

#wall_timeObject (readonly)

Returns the value of attribute wall_time.



49
50
51
# File 'lib/megatest/executor.rb', line 49

def wall_time
  @wall_time
end

Instance Method Details

#concurrent?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/megatest/executor.rb', line 56

def concurrent?
  false
end

#run(queue, reporters) ⇒ Object



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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/megatest/executor.rb', line 60

def run(queue, reporters)
  start_time = Megatest.now

  @config.run_global_setup_callbacks
  @config.run_job_setup_callbacks(nil)

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

  reporters.each { |r| r.start(self, queue) }

  runner = Runner.new(@config)

  begin
    while true
      if test_case = queue.pop_test
        reporters.each { |r| r.before_test_case(queue, test_case) }

        result = runner.execute(test_case)

        result = queue.record_result(result)
        reporters.each { |r| r.after_test_case(queue, test_case, result) }

        @config.circuit_breaker.record_result(result)
        break if @config.circuit_breaker.break?
      elsif queue.empty?
        break
      else
        # There was no tests to pop, but not all tests are completed.
        # So we stick around to pop tests that could be lost.
        sleep(1)
      end
    end
  rescue Interrupt
    # Early exit
  end

  monitor&.reap

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

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

  @config.run_job_teardown_callbacks(nil)

  queue.cleanup
end