Module: Minitest::Queue

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.



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

def project_root=(value)
  @project_root = value
end

#queueObject

Returns the value of attribute queue.



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

def queue
  @queue
end

#run_command_formatterObject



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

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



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

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

.relative_path(path, root: project_root) ⇒ Object



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

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



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

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



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

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



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

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



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

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



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

def run_from_queue(reporter, *)
  queue.poll do |example|
    result = example.run
    failed = !(result.passed? || result.skipped?)

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

    if failed
      queue.report_failure!
    else
      queue.report_success!
    end

    requeued = false
    if failed && CI::Queue.requeueable?(result) && queue.requeue(example)
      requeued = true
      result.requeue!
      reporter.record(result)
    elsif queue.acknowledge(example) || !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

    if !requeued && failed
      queue.increment_test_failed
    end
  end
end