module RSpec::Queue::ExampleExtension

Protected Instance Methods

mark_as_requeued!(reporter) click to toggle source
# File lib/rspec/queue.rb, line 173
def mark_as_requeued!(reporter)
  @metadata = @metadata.dup # Avoid mutating the @metadata hash of the original Example instance
  @metadata[:execution_result] = execution_result.dup


  failure_notification = RSpec::Core::Notifications::FailedExampleNotification.new(self)
  execution_result.exception = @exception
  execution_result.status = :failed

  presenter = RSpec::Core::Formatters::ExceptionPresenter::Factory.new(self).build
  error_message = presenter.fully_formatted_lines(nil, ::RSpec::Core::Formatters::ConsoleCodes)
  error_message.delete_at(1) # remove the example description

  @exception = nil
  execution_result.exception = nil
  execution_result.status = :pending
  execution_result.pending_message = [
    "The example failed, but another attempt will be done to rule out flakiness",
    *error_message.map { |l| l.empty? ? l : "   " + l },
  ].join("\n")

  # Ensure the example is recorded as ran, so it's visible to formatters
  reporter.example_started(self)
  finish(reporter, acknowledge: false)
end

Private Instance Methods

finish(reporter, acknowledge: true) click to toggle source
Calls superclass method
# File lib/rspec/queue.rb, line 206
def finish(reporter, acknowledge: true)
  if acknowledge && reporter.respond_to?(:requeue)
    if @exception
      reporter.report_failure!
    else
      reporter.report_success!
    end

    if @exception && CI::Queue.requeueable?(@exception) && reporter.requeue
      reporter.cancel_run!
      dup.mark_as_requeued!(reporter)
      return true
    elsif reporter.acknowledge || !@exception
      # If the test was already acknowledged by another worker (we timed out)
      # Then we only record it if it is successful.
      super(reporter)
    else
      reporter.cancel_run!
      return
    end
  else
    super(reporter)
  end
end
reset!() click to toggle source
# File lib/rspec/queue.rb, line 231
def reset!
  @exception = nil
  @metadata[:execution_result] = RSpec::Core::Example::ExecutionResult.new
end
start(*) click to toggle source
Calls superclass method
# File lib/rspec/queue.rb, line 201
def start(*)
  reset! # In case that example was already ran but got requeued
  super
end