class Minitest::Distributed::EnqueuedRunnable

Public Class Methods

from_redis_stream_claim(claims, pending_messages = {}, configuration:) click to toggle source
# File lib/minitest/distributed/enqueued_runnable.rb, line 129
def from_redis_stream_claim(claims, pending_messages = {}, configuration:)
  claims.map do |entry_id, runnable_method_info|
    # `attempt` will be set to the current attempt of a different worker that has timed out.
    # The attempt we are going to try will be the next one, so add one.
    attempt = pending_messages.key?(entry_id) ? pending_messages.fetch(entry_id).attempt + 1 : 1

    new(
      class_name: runnable_method_info.fetch("class_name"),
      method_name: runnable_method_info.fetch("method_name"),
      entry_id: entry_id,
      attempt: attempt,
      max_attempts: configuration.max_attempts,
      test_timeout_seconds: configuration.test_timeout_seconds,
    )
  end
end

Public Instance Methods

attempt_id() click to toggle source
# File lib/minitest/distributed/enqueued_runnable.rb, line 162
def attempt_id
  "#{entry_id}/#{attempt}"
end
attempts_exhausted?() click to toggle source
# File lib/minitest/distributed/enqueued_runnable.rb, line 177
def attempts_exhausted?
  attempt > max_attempts
end
attempts_exhausted_result() click to toggle source
# File lib/minitest/distributed/enqueued_runnable.rb, line 187
      def attempts_exhausted_result
        assertion = Minitest::AttemptsExhausted.new(<<~EOM.chomp)
          This test takes too long to run (> #{test_timeout_seconds}s).

          We have tried running this test #{max_attempts} on different workers, but every time the worker has not reported back a result within #{test_timeout_seconds}s.
          Try to make the test faster, or increase the test timeout.
        EOM
        assertion.set_backtrace(caller)

        runnable = instantiate_runnable
        runnable.time = 0.0
        runnable.failures = [assertion]

        Minitest::Result.from(runnable)
      end
commit_result(initial_result, &block) click to toggle source
# File lib/minitest/distributed/enqueued_runnable.rb, line 209
def commit_result(initial_result, &block)
  EnqueuedRunnable::Result.new(
    enqueued_runnable: self,
    initial_result: initial_result,
    commit: block.call(initial_result),
  )
end
final_attempt?() click to toggle source
# File lib/minitest/distributed/enqueued_runnable.rb, line 182
def final_attempt?
  attempt == max_attempts
end
identifier() click to toggle source
# File lib/minitest/distributed/enqueued_runnable.rb, line 157
def identifier
  "#{class_name}##{method_name}"
end
instantiate_runnable() click to toggle source
# File lib/minitest/distributed/enqueued_runnable.rb, line 172
def instantiate_runnable
  runnable_class.new(method_name)
end
next_attempt() click to toggle source
# File lib/minitest/distributed/enqueued_runnable.rb, line 233
def next_attempt
  self.class.new(
    class_name: class_name,
    method_name: method_name,
    entry_id: entry_id,
    attempt: attempt + 1,
    max_attempts: max_attempts,
    test_timeout_seconds: test_timeout_seconds,
  )
end
run() click to toggle source
# File lib/minitest/distributed/enqueued_runnable.rb, line 218
def run
  if attempts_exhausted?
    attempts_exhausted_result
  else
    result = Minitest.run_one_method(runnable_class, method_name)
    result_type = ResultType.of(result)
    if (result_type == ResultType::Error || result_type == ResultType::Failed) && !final_attempt?
      Minitest::Requeue.wrap(result, attempt: attempt, max_attempts: max_attempts)
    else
      result
    end
  end
end
runnable_class() click to toggle source
# File lib/minitest/distributed/enqueued_runnable.rb, line 167
def runnable_class
  DefinedRunnable.find_class(class_name)
end