Module: Minitest::Queue

Extended by:
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.



273
274
275
# File 'lib/minitest/queue.rb', line 273

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

.handle_test_result(reporter, example, result) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/minitest/queue.rb', line 171

def handle_test_result(reporter, example, result)
  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!
  end
  reporter.record(result)
end

.project_rootObject



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

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

.queueObject



153
154
155
# File 'lib/minitest/queue.rb', line 153

def queue
  Minitest.queue
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

.run(reporter) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/minitest/queue.rb', line 157

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

      handle_test_result(reporter, example, result)
    end

    queue.stop_heartbeat!
  end
end

Instance Method Details

#__run(*args) ⇒ Object



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/minitest/queue.rb', line 290

def __run(*args)
  if queue
    Queue.run(*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



282
283
284
285
286
287
288
# File 'lib/minitest/queue.rb', line 282

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



275
276
277
278
279
280
# File 'lib/minitest/queue.rb', line 275

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