mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08: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:
@ -14,10 +14,6 @@ class Autospec::Formatter < RSpec::Core::Formatters::BaseTextFormatter
|
||||
def initialize(output)
|
||||
super
|
||||
FileUtils.mkdir_p("tmp") unless Dir.exists?("tmp")
|
||||
end
|
||||
|
||||
def start(example_count)
|
||||
super
|
||||
File.delete(RSPEC_RESULT) if File.exists?(RSPEC_RESULT)
|
||||
@fail_file = File.open(RSPEC_RESULT, "w")
|
||||
end
|
||||
@ -32,7 +28,7 @@ class Autospec::Formatter < RSpec::Core::Formatters::BaseTextFormatter
|
||||
|
||||
def example_failed(notification)
|
||||
output.print RSpec::Core::Formatters::ConsoleCodes.wrap('F', :failure)
|
||||
@fail_file.puts(notification.example.metadata[:location] + " ")
|
||||
@fail_file.puts(notification.example.location + " ")
|
||||
@fail_file.flush
|
||||
end
|
||||
|
||||
@ -46,17 +42,3 @@ class Autospec::Formatter < RSpec::Core::Formatters::BaseTextFormatter
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Autospec::ParallelFormatter < ParallelTests::RSpec::LoggerBase
|
||||
RSpec::Core::Formatters.register self, :example_failed
|
||||
|
||||
def message(*args);end
|
||||
def dump_failures(*args);end
|
||||
def dump_summary(*args);end
|
||||
def dump_pending(*args);end
|
||||
def seed(*args);end
|
||||
|
||||
def example_failed(notification)
|
||||
output.puts notification.example.metadata[:location] + " "
|
||||
end
|
||||
end
|
||||
|
@ -16,18 +16,17 @@ module Autospec
|
||||
self.abort
|
||||
end
|
||||
# we use our custom rspec formatter
|
||||
args = ["-r", "#{File.dirname(__FILE__)}/formatter.rb"]
|
||||
args = [
|
||||
"-r", "#{File.dirname(__FILE__)}/formatter.rb",
|
||||
"-f", "Autospec::Formatter"
|
||||
]
|
||||
|
||||
command = begin
|
||||
if ENV["PARALLEL_SPEC"] &&
|
||||
if ENV["PARALLEL_SPEC"] != '0' &&
|
||||
!specs.split.any? { |s| puts s; s =~ /\:/ } # Parallel spec can't run specific groups
|
||||
|
||||
args += ["-f", "progress", "-f", "Autospec::ParallelFormatter", "-o", "./tmp/rspec_result"]
|
||||
args += ["-f", "ParallelTests::RSpec::RuntimeLogger", "-o", "./tmp/parallel_runtime_rspec.log"] if specs == "spec"
|
||||
|
||||
"parallel_rspec -- #{args.join(" ")} -- #{specs.split.join(" ")}"
|
||||
"bin/turbo_rspec #{args.join(" ")} #{specs.split.join(" ")}"
|
||||
else
|
||||
args += ["-f", "Autospec::Formatter"]
|
||||
"bin/rspec #{args.join(" ")} #{specs.split.join(" ")}"
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user