Skip to content
Permalink
Browse files

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
  • Loading branch information...
davidtaylorhq authored and eviltrout committed Apr 1, 2019
1 parent 13a6a04 commit b375dcb14a60bf83ee2e1ef23acdca95bb4ce40d
Showing with 28 additions and 0 deletions.
  1. +4 −0 .rspec_parallel
  2. +1 −0 Gemfile
  3. +3 −0 Gemfile.lock
  4. +4 −0 app/models/global_setting.rb
  5. +16 −0 config/boot.rb
@@ -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
@@ -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
@@ -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
@@ -236,6 +236,10 @@ def keys

class BlankProvider < BaseProvider
def lookup(key, default)

if key == :redis_port
return ENV["DISCOURSE_REDIS_PORT"] if ENV["DISCOURSE_REDIS_PORT"]
end
default
end

@@ -28,3 +28,19 @@
)
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

0 comments on commit b375dcb

Please sign in to comment.
You can’t perform that action at this time.