DEV: Introduce parallel rspec testing

Adds the parallel_tests gem, and redis/postgres configuration for running rspec tests in parallel. To use:

```
rake parallel:rake[db:create]
rake parallel:rake[db:migrate]
rake parallel:spec
```

This brings the test suite from 12m20s to 3m11s on my macOS machine
This commit is contained in:
David Taylor 2019-04-01 09:27:49 +01:00 committed by Robin Ward
parent 13a6a04cad
commit b375dcb14a
5 changed files with 28 additions and 0 deletions

4
.rspec_parallel Normal file
View File

@ -0,0 +1,4 @@
--format progress
--format ParallelTests::RSpec::RuntimeLogger --out tmp/parallel_runtime_rspec.log
--format ParallelTests::RSpec::SummaryLogger --out tmp/spec_summary.log
--format ParallelTests::RSpec::FailuresLogger --out tmp/failing_specs.log

View File

@ -140,6 +140,7 @@ group :test, :development do
gem 'pry-nav'
gem 'byebug', require: ENV['RM_INFO'].nil?
gem 'rubocop', require: false
gem 'parallel_tests'
end
group :development do

View File

@ -276,6 +276,8 @@ GEM
ruby-openid
optimist (3.0.0)
parallel (1.13.0)
parallel_tests (2.28.0)
parallel
parser (2.6.0.0)
ast (~> 2.4.0)
pg (1.1.4)
@ -524,6 +526,7 @@ DEPENDENCIES
omniauth-twitter
onebox (= 1.8.82)
openid-redis-store
parallel_tests
pg
pry-nav
pry-rails

View File

@ -236,6 +236,10 @@ class GlobalSetting
class BlankProvider < BaseProvider
def lookup(key, default)
if key == :redis_port
return ENV["DISCOURSE_REDIS_PORT"] if ENV["DISCOURSE_REDIS_PORT"]
end
default
end

View File

@ -28,3 +28,19 @@ if ENV['RAILS_ENV'] != 'production' && ENV['RAILS_ENV'] != 'profile'
)
end
end
# Parallel spec system
if ENV['RAILS_ENV'] == "test" && ENV['TEST_ENV_NUMBER']
n = ENV['TEST_ENV_NUMBER'].to_i
port = 10000 + n
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']}"
at_exit { puts "Terminating redis #{n}"; Process.kill("SIGTERM", pid); Process.wait }
end