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

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