mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Add a new way to run specs in parallel with better output (#7778)
* DEV: Add a new way to run specs in parallel with better output
This commit:
1. adds a new executable, `bin/interleaved_rspec` which works much like
`rspec`, but runs the tests in parallel.
2. adds a rake task, `rake interleaved:spec` which runs the whole test
suite.
3. makes autospec use this new wrapper by default. You can disable this
by running `PARALLEL_SPEC=0 rake autospec`.
It works much like the `parallel_tests` gem (and relies on it), but
makes each subprocess use a machine-readable formatter and parses this
output in order to provide a better overall summary.
(It's called interleaved, because parallel was taken and naming is
hard).
* Make popen3 invocation safer
* Use FileUtils instead of shelling out
* DRY up reporter
* Moved summary logic into Reporter
* s/interleaved/turbo/g
* Move Reporter into its own file
* Moved run into its own class
* Moved Runner into its own file
* Move JsonRowsFormatter under TurboTests
* Join on threads at the end
* Acted on feedback from eviltrout
This commit is contained in:
103
lib/turbo_tests/reporter.rb
Normal file
103
lib/turbo_tests/reporter.rb
Normal file
@@ -0,0 +1,103 @@
|
||||
module TurboTests
|
||||
class Reporter
|
||||
def self.from_config(formatter_config, start_time)
|
||||
reporter = new(start_time)
|
||||
|
||||
formatter_config.each do |config|
|
||||
name, outputs = config.values_at(:name, :outputs)
|
||||
|
||||
outputs.map! do |filename|
|
||||
filename == '-' ? STDOUT : File.open(filename, 'w')
|
||||
end
|
||||
|
||||
reporter.add(name, outputs)
|
||||
end
|
||||
|
||||
reporter
|
||||
end
|
||||
|
||||
attr_reader :pending_examples
|
||||
attr_reader :failed_examples
|
||||
|
||||
def initialize(start_time)
|
||||
@formatters = []
|
||||
@pending_examples = []
|
||||
@failed_examples = []
|
||||
@all_examples = []
|
||||
@start_time = start_time
|
||||
end
|
||||
|
||||
def add(name, outputs)
|
||||
outputs.each do |output|
|
||||
formatter_class =
|
||||
case name
|
||||
when 'p', 'progress'
|
||||
RSpec::Core::Formatters::ProgressFormatter
|
||||
else
|
||||
Kernel.const_get(name)
|
||||
end
|
||||
|
||||
@formatters << formatter_class.new(output)
|
||||
end
|
||||
end
|
||||
|
||||
def example_passed(example)
|
||||
delegate_to_formatters(:example_passed, example.notification)
|
||||
|
||||
@all_examples << example
|
||||
end
|
||||
|
||||
def example_pending(example)
|
||||
delegate_to_formatters(:example_pending, example.notification)
|
||||
|
||||
@all_examples << example
|
||||
@pending_examples << example
|
||||
end
|
||||
|
||||
def example_failed(example)
|
||||
delegate_to_formatters(:example_failed, example.notification)
|
||||
|
||||
@all_examples << example
|
||||
@failed_examples << example
|
||||
end
|
||||
|
||||
def finish
|
||||
end_time = Time.now
|
||||
|
||||
delegate_to_formatters(:start_dump,
|
||||
RSpec::Core::Notifications::NullNotification
|
||||
)
|
||||
delegate_to_formatters(:dump_pending,
|
||||
RSpec::Core::Notifications::ExamplesNotification.new(
|
||||
self
|
||||
)
|
||||
)
|
||||
delegate_to_formatters(:dump_failures,
|
||||
RSpec::Core::Notifications::ExamplesNotification.new(
|
||||
self
|
||||
)
|
||||
)
|
||||
delegate_to_formatters(:dump_summary,
|
||||
RSpec::Core::Notifications::SummaryNotification.new(
|
||||
end_time - @start_time,
|
||||
@all_examples,
|
||||
@failed_examples,
|
||||
@pending_examples,
|
||||
0,
|
||||
0
|
||||
)
|
||||
)
|
||||
delegate_to_formatters(:close,
|
||||
RSpec::Core::Notifications::NullNotification
|
||||
)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def delegate_to_formatters(method, *args)
|
||||
@formatters.each do |formatter|
|
||||
formatter.send(method, *args) if formatter.respond_to?(method)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user