Skip to content

Commit

Permalink
Merge pull request skroutz#1 from kyler-instructure/junit_report_init…
Browse files Browse the repository at this point in the history
…ial_failure

Junit report initial failure
  • Loading branch information
jbutte authored Nov 11, 2021
2 parents a49343f + baeb5c6 commit f3a1c2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
23 changes: 16 additions & 7 deletions lib/rspecq/formatters/junit_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,43 @@ def initialize(queue, job, max_requeues, job_index, path)
@queue = queue
@job = job
@max_requeues = max_requeues
@requeued_examples = []
@requeued_passed_examples = []
@requeued_failed_examples = []
path = path.gsub(/{{TEST_ENV_NUMBER}}/,ENV["TEST_ENV_NUMBER"].to_s)
path = path.gsub(/{{JOB_INDEX}}/, job_index.to_s)
RSpec::Support::DirectoryMaker.mkdir_p(File.dirname(path))
output_file = File.new(path, "w")
super(output_file)
end

def example_passed(notification)
# if it is a requeued run, store the notification
if !ENV["ERROR_CONTEXT_BASE_PATH"].nil?
@requeued_passed_examples << notification.example
end
end

def example_failed(notification)
# if it is requeued, store the notification
if @queue.requeueable_job?(notification.example.id, @max_requeues)
@requeued_examples << notification.example
# if it is a requeued run, store the notification
if !ENV["ERROR_CONTEXT_BASE_PATH"].nil?
@requeued_failed_examples << notification.example
end
end

private

def example_count
@summary_notification.example_count - @requeued_examples.size
@summary_notification.example_count - (@requeued_passed_examples.size + @requeued_failed_examples.size)
end

def failure_count
@summary_notification.failure_count - @requeued_examples.size
@summary_notification.failure_count - @requeued_failed_examples.size
end

def examples
ignore_examples = @requeued_failed_examples.union(@requeued_passed_examples)
@examples_notification.notifications.reject do |example_notification|
@requeued_examples.map(&:id).include?(example_notification.example.id)
ignore_examples.map(&:id).include?(example_notification.example.id)
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/rspecq/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def initialize(build_id:, worker_id:, redis_opts:)
RSpec::Core::Formatters.register(Formatters::ExampleCountRecorder, :dump_summary)
RSpec::Core::Formatters.register(Formatters::FailureRecorder, :example_failed, :message)
RSpec::Core::Formatters.register(Formatters::WorkerHeartbeatRecorder, :example_finished)
RSpec::Core::Formatters.register(Formatters::JUnitFormatter, :example_failed, :start, :stop, :dump_summary)
RSpec::Core::Formatters.register(Formatters::JUnitFormatter, :example_passed, :example_failed, :start, :stop, :dump_summary)
end

def work
Expand Down Expand Up @@ -126,6 +126,7 @@ def work
puts
puts "Executing #{job}"

ENV["ERROR_CONTEXT_BASE_PATH"] = nil
unless queue.is_requeue(job).nil?
ENV["ERROR_CONTEXT_BASE_PATH"] = "/usr/src/app/log/spec_failures/Rerun_#{queue.is_requeue(job)}"
end
Expand Down

0 comments on commit f3a1c2f

Please sign in to comment.