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
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
45 lines
1.1 KiB
Ruby
45 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rspec/core/formatters/base_text_formatter"
|
|
require "parallel_tests/rspec/logger_base"
|
|
|
|
module Autospec; end
|
|
|
|
class Autospec::Formatter < RSpec::Core::Formatters::BaseTextFormatter
|
|
|
|
RSpec::Core::Formatters.register self, :example_passed, :example_pending, :example_failed, :start_dump
|
|
|
|
RSPEC_RESULT = "./tmp/rspec_result"
|
|
|
|
def initialize(output)
|
|
super
|
|
FileUtils.mkdir_p("tmp") unless Dir.exists?("tmp")
|
|
File.delete(RSPEC_RESULT) if File.exists?(RSPEC_RESULT)
|
|
@fail_file = File.open(RSPEC_RESULT, "w")
|
|
end
|
|
|
|
def example_passed(_notification)
|
|
output.print RSpec::Core::Formatters::ConsoleCodes.wrap('.', :success)
|
|
end
|
|
|
|
def example_pending(_notification)
|
|
output.print RSpec::Core::Formatters::ConsoleCodes.wrap('*', :pending)
|
|
end
|
|
|
|
def example_failed(notification)
|
|
output.print RSpec::Core::Formatters::ConsoleCodes.wrap('F', :failure)
|
|
@fail_file.puts(notification.example.location + " ")
|
|
@fail_file.flush
|
|
end
|
|
|
|
def start_dump(notification)
|
|
output.puts
|
|
end
|
|
|
|
def close(filename)
|
|
@fail_file.close
|
|
super(filename)
|
|
end
|
|
|
|
end
|