Module: Minitest::Queue

Includes:
CI::Queue::OutputHelpers
Defined in:
lib/minitest/queue.rb,
lib/minitest/queue/runner.rb,
lib/minitest/queue/statsd.rb,
lib/minitest/queue/test_data.rb,
lib/minitest/queue/error_report.rb,
lib/minitest/queue/grind_recorder.rb,
lib/minitest/queue/grind_reporter.rb,
lib/minitest/queue/junit_reporter.rb,
lib/minitest/queue/failure_formatter.rb,
lib/minitest/queue/test_data_reporter.rb,
lib/minitest/queue/test_time_recorder.rb,
lib/minitest/queue/test_time_reporter.rb,
lib/minitest/queue/build_status_recorder.rb,
lib/minitest/queue/build_status_reporter.rb,
lib/minitest/queue/local_requeue_reporter.rb

Defined Under Namespace

Classes: BuildStatusRecorder, BuildStatusReporter, ErrorReport, FailureFormatter, GrindRecorder, GrindReporter, JUnitReporter, LocalRequeueReporter, OrderReporter, Runner, SingleExample, Statsd, TestData, TestDataReporter, TestTimeRecorder, TestTimeReporter

Constant Summary collapse

DEFAULT_RUN_COMMAND_FORMATTER =
lambda do |runnable|
  filename = Minitest::Queue.relative_path(runnable.source_location[0])
  identifier = "#{runnable.klass}##{runnable.name}"
  ['bundle', 'exec', 'ruby', '-Ilib:test', filename, '-n', identifier]
end
RAILS_RUN_COMMAND_FORMATTER =
lambda do |runnable|
  filename = Minitest::Queue.relative_path(runnable.source_location[0])
  lineno = runnable.source_location[1]
  ['bin/rails', 'test', "#{filename}:#{lineno}"]
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#project_root=(value) ⇒ Object (writeonly)

Sets the attribute project_root

Parameters:

  • value

    the value to set the attribute project_root to.



111
112
113
# File 'lib/minitest/queue.rb', line 111

def project_root=(value)
  @project_root = value
end

#queueObject

Returns the value of attribute queue.



195
196
197
# File 'lib/minitest/queue.rb', line 195

def queue
  @queue
end

#run_command_formatterObject



113
114
115
116
117
118
119
# File 'lib/minitest/queue.rb', line 113

def run_command_formatter
  @run_command_formatter ||= if defined?(Rails) && defined?(Rails::TestUnitRailtie)
    RAILS_RUN_COMMAND_FORMATTER
  else
    DEFAULT_RUN_COMMAND_FORMATTER
  end
end

Class Method Details

.project_rootObject



142
143
144
# File 'lib/minitest/queue.rb', line 142

def self.project_root
  @project_root ||= Dir.pwd
end

.relative_path(path, root: project_root) ⇒ Object



146
147
148
149
150
# File 'lib/minitest/queue.rb', line 146

def self.relative_path(path, root: project_root)
  Pathname(path).relative_path_from(Pathname(root)).to_s
rescue ArgumentError, TypeError
  path
end

Instance Method Details

#__run(*args) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/minitest/queue.rb', line 212

def __run(*args)
  if queue
    run_from_queue(*args)

    if queue.config.circuit_breakers.any?(&:open?)
      STDERR.puts queue.config.circuit_breakers.map(&:message).join(' ').strip
    end

    if queue.max_test_failed?
      STDERR.puts 'This worker is exiting early because too many failed tests were encountered.'
    end
  else
    super
  end
end

#loaded_testsObject



204
205
206
207
208
209
210
# File 'lib/minitest/queue.rb', line 204

def loaded_tests
  Minitest::Test.runnables.flat_map do |runnable|
    runnable.runnable_methods.map do |method_name|
      SingleExample.new(runnable, method_name)
    end
  end
end

#queue_reporters=(reporters) ⇒ Object



197
198
199
200
201
202
# File 'lib/minitest/queue.rb', line 197

def queue_reporters=(reporters)
  @queue_reporters ||= []
  Reporters.use!(((Reporters.reporters || []) - @queue_reporters) + reporters)
  Minitest.backtrace_filter.add_filter(%r{exe/minitest-queue|lib/ci/queue/})
  @queue_reporters = reporters
end

#run_command_for_runnable(runnable) ⇒ Object



133
134
135
136
137
138
139
140
# File 'lib/minitest/queue.rb', line 133

def run_command_for_runnable(runnable)
  command = run_command_formatter.call(runnable)
  if command.is_a?(Array)
    Shellwords.join(command)
  else
    command
  end
end

#run_from_queue(reporter) ⇒ Object



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
269
# File 'lib/minitest/queue.rb', line 228

def run_from_queue(reporter, *)
  queue.poll do |example|
    result = queue.with_heartbeat(example.id) do
      example.run
    end

    failed = !(result.passed? || result.skipped?)

    if example.flaky?
      result.mark_as_flaked!
      failed = false
    end

    if failed && queue.config.failing_test && queue.config.failing_test != example.id
      # When we do a bisect, we don't care about the result other than the test we're running the bisect on
      result.mark_as_flaked!
      failed = false
    elsif failed
      queue.report_failure!
    else
      queue.report_success!
    end

    if failed && CI::Queue.requeueable?(result) && queue.requeue(example)
      result.requeue!
      reporter.record(result)
    elsif queue.acknowledge(example)
      reporter.record(result)
      queue.increment_test_failed if failed
    elsif !failed
      # If the test was already acknowledged by another worker (we timed out)
      # Then we only record it if it is successful.
      reporter.record(result)
    end
  end
  queue.stop_heartbeat!
rescue Errno::EPIPE
  # This happens when the heartbeat process dies
  reopen_previous_step
  puts red("The heartbeat process died. This worker is exiting early.")
  exit!(41)
end