diff --git a/lib/parallel_cucumber/helper/cucumber/cucumber.rb b/lib/parallel_cucumber/helper/cucumber/cucumber.rb index ffa22d3..e667da4 100644 --- a/lib/parallel_cucumber/helper/cucumber/cucumber.rb +++ b/lib/parallel_cucumber/helper/cucumber/cucumber.rb @@ -26,25 +26,25 @@ def batch_mapped_files(options, batch, env) def parse_json_report(json_report) report = JSON.parse(json_report, symbolize_names: true) - report.map do |scenario, cucumber_status| - status = case cucumber_status - when 'failed' - Status::FAILED - when 'passed' - Status::PASSED - when 'pending' - Status::PENDING - when 'skipped' - Status::SKIPPED - when 'undefined' - Status::UNDEFINED - when 'unknown' - Status::UNKNOWN - else - Status::UNKNOWN - end - [scenario, status] - end.to_h + report.each do |scenario, details| + report[scenario][:status] = case details[:status] + when 'failed' + Status::FAILED + when 'passed' + Status::PASSED + when 'pending' + Status::PENDING + when 'skipped' + Status::SKIPPED + when 'undefined' + Status::UNDEFINED + when 'unknown' + Status::UNKNOWN + else + Status::UNKNOWN + end + end + report end private @@ -57,7 +57,7 @@ def dry_run_report(options, args_string) options = remove_strict_flag(options) content = nil - Tempfile.open(%w(dry-run .json)) do |f| + Tempfile.open(%w[dry-run .json]) do |f| dry_run_options = "--dry-run --format ParallelCucumber::Helper::Cucumber::JsonStatusFormatter --out #{f.path}" cmd = "cucumber #{options} #{dry_run_options} #{args_string}" diff --git a/lib/parallel_cucumber/helper/cucumber/json_status_formatter.rb b/lib/parallel_cucumber/helper/cucumber/json_status_formatter.rb index b6cfd9b..f9328f5 100644 --- a/lib/parallel_cucumber/helper/cucumber/json_status_formatter.rb +++ b/lib/parallel_cucumber/helper/cucumber/json_status_formatter.rb @@ -15,7 +15,13 @@ def initialize(config) end def on_after_test_case(event) - @result[event.test_case.location.to_s] = event.result.to_sym + details = {status: event.result.to_sym} + if event.result.respond_to?(:exception) + details[:exception_classname] = event.result.exception.class.to_s + details[:exception_message] = event.result.exception.message + end + details[:finish_time] = Time.now.to_i + @result[event.test_case.location.to_s] = details end def on_finished_testing(*) diff --git a/lib/parallel_cucumber/main.rb b/lib/parallel_cucumber/main.rb index 19a3b55..c6f4755 100644 --- a/lib/parallel_cucumber/main.rb +++ b/lib/parallel_cucumber/main.rb @@ -98,7 +98,7 @@ def run status_totals = Status.constants.map do |status| status = Status.const_get(status) - tests_with_status = results.select { |_t, s| s == status }.keys + tests_with_status = results.select { |_t, s| s[:status] == status }.keys [status, tests_with_status] end.to_h diff --git a/lib/parallel_cucumber/worker.rb b/lib/parallel_cucumber/worker.rb index f585f0d..379168f 100644 --- a/lib/parallel_cucumber/worker.rb +++ b/lib/parallel_cucumber/worker.rb @@ -176,7 +176,7 @@ def precheck(env) def running_totals(batch_results, running_total) batch_info = Status.constants.map do |status| status = Status.const_get(status) - [status, batch_results.select { |_t, s| s == status }.keys] + [status, batch_results.select { |_t, s| s[:status] == status }.keys] end.to_h batch_info.each do |s, tt| @logger.info("#{s.to_s.upcase} #{tt.count} tests: #{tt.join(' ')}") unless tt.empty? @@ -191,7 +191,7 @@ def process_results(batch_results, tests) test_syms = tests.map(&:to_sym) unrun = test_syms - batch_keys surfeit = batch_keys - test_syms - unrun.each { |test| batch_results[test] = Status::UNKNOWN } + unrun.each { |test| batch_results[test][:status] = Status::UNKNOWN } surfeit.each { |test| batch_results.delete(test) } @logger.error("Did not run #{unrun.count}/#{tests.count}: #{unrun.join(' ')}") unless unrun.empty? @logger.error("Extraneous runs (#{surfeit.count}): #{surfeit.join(' ')}") unless surfeit.empty? diff --git a/lib/parallel_cucumber/worker_manager.rb b/lib/parallel_cucumber/worker_manager.rb index e3d1437..2d8119e 100644 --- a/lib/parallel_cucumber/worker_manager.rb +++ b/lib/parallel_cucumber/worker_manager.rb @@ -39,7 +39,7 @@ def inform_idle(worker) def create_workers(number_of_workers) number_of_workers.times do |index| @workers["W#{index}"] = - ParallelCucumber::Worker.new(options: @options, index: index, stdout_logger: @logger, manager: self) + ParallelCucumber::Worker.new(options: @options, index: index, stdout_logger: @logger, manager: self) end end @@ -67,11 +67,15 @@ def start_workers puts "Starting W#{index}" @workers["W#{index}"].start(env_for_worker(@options[:env_variables], index)) end - @results.inject(:merge) # Returns hash of file:line to statuses + :worker-index to summary. + @results.inject do |seed, result| + seed.merge(result) do |_key, oldval, newval| + (newval[:finish_time] > oldval[:finish_time]) ? newval : oldval + end + end end def kill_all_workers - @logger.info("=== Killing All Workers") + @logger.info('=== Killing All Workers') @workers.values.each { |w| w.assign_job(Job.new(Job::DIE)) } end