From 24adaa095a5968c4412b87221ff67ca115fd0657 Mon Sep 17 00:00:00 2001 From: Will Jordan Date: Sun, 19 Apr 2020 17:45:43 -0700 Subject: [PATCH] Support parallel tests in verbose progress reporting (#2223) * Support parallel tests in verbose progress reporting Reports correct duration and status for tests run in parallel threads. * manually load verbose_progress minitest plugin --- History.md | 1 + test/helper.rb | 1 + test/minitest/verbose.rb | 5 ++++ test/minitest/verbose_progress_plugin.rb | 34 ++++++++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 test/minitest/verbose.rb create mode 100644 test/minitest/verbose_progress_plugin.rb diff --git a/History.md b/History.md index f7a67f01..b42ebbda 100644 --- a/History.md +++ b/History.md @@ -42,6 +42,7 @@ * Update `Rack::Handler::Puma.run` to use `**options` (#2189) * ThreadPool concurrency refactoring (#2220) * JSON parse cluster worker stats instead of regex (#2124) + * Support parallel tests in verbose progress reporting (#2223) ## 4.3.3 and 3.12.4 / 2020-02-28 diff --git a/test/helper.rb b/test/helper.rb index d482012b..fe190b6c 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -11,6 +11,7 @@ if %w(2.2.7 2.2.8 2.2.9 2.2.10 2.3.4 2.4.1).include? RUBY_VERSION end end +require_relative "minitest/verbose" require "minitest/autorun" require "minitest/pride" require "minitest/proveit" diff --git a/test/minitest/verbose.rb b/test/minitest/verbose.rb new file mode 100644 index 00000000..0f4747fa --- /dev/null +++ b/test/minitest/verbose.rb @@ -0,0 +1,5 @@ +require "minitest" +require_relative "verbose_progress_plugin" + +Minitest.load_plugins +Minitest.extensions << 'verbose_progress' unless Minitest.extensions.include?('verbose_progress') diff --git a/test/minitest/verbose_progress_plugin.rb b/test/minitest/verbose_progress_plugin.rb new file mode 100644 index 00000000..4c905e68 --- /dev/null +++ b/test/minitest/verbose_progress_plugin.rb @@ -0,0 +1,34 @@ +module Minitest + # Adds minimal support for parallel tests to the default verbose progress reporter. + def self.plugin_verbose_progress_init(options) + if options[:verbose] + self.reporter.reporters. + delete_if {|r| r.is_a?(ProgressReporter)}. + push(VerboseProgressReporter.new(options[:io], options)) + end + end + + # Verbose progress reporter that supports parallel test execution. + class VerboseProgressReporter < Reporter + def prerecord(klass, name) + @current ||= nil + @current = [klass.name, name].tap(&method(:print_start)) + end + + def record(result) + print_start [result.klass, result.name] + @current = nil + io.print "%.2f s = " % [result.time] + io.print result.result_code + io.puts + end + + def print_start(test) + unless @current == test + io.puts '…' if @current + io.print "%s#%s = " % test + io.flush + end + end + end +end