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:
Daniel Waterworth
2019-06-21 01:59:01 +01:00
committed by Sam
parent 9f0574dcfd
commit e18ce56f4b
9 changed files with 460 additions and 30 deletions

View File

@ -33,16 +33,21 @@ end
# Parallel spec system
if ENV['RAILS_ENV'] == "test" && ENV['TEST_ENV_NUMBER']
n = ENV['TEST_ENV_NUMBER'].to_i
if ENV['TEST_ENV_NUMBER'] == ''
n = 1
else
n = ENV['TEST_ENV_NUMBER'].to_i
end
port = 10000 + n
puts "Setting up parallel test mode - starting Redis #{n} on port #{port}"
STDERR.puts "Setting up parallel test mode - starting Redis #{n} on port #{port}"
`rm -rf tmp/test_data_#{n} && mkdir -p tmp/test_data_#{n}/redis`
pid = Process.spawn("redis-server --dir tmp/test_data_#{n}/redis --port #{port}", out: "/dev/null")
ENV["DISCOURSE_REDIS_PORT"] = port.to_s
ENV["RAILS_DB"] = "discourse_test_#{ENV['TEST_ENV_NUMBER']}"
ENV["RAILS_DB"] = "discourse_test_#{n}"
at_exit { puts "Terminating redis #{n}"; Process.kill("SIGTERM", pid); Process.wait }
at_exit { STDERR.puts "Terminating redis #{n}"; Process.kill("SIGTERM", pid); Process.wait }
end