Skip to content

Commit

Permalink
DEV: Introduce parallel rspec testing
Browse files Browse the repository at this point in the history
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 b375dcb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .rspec_parallel
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -524,6 +526,7 @@ DEPENDENCIES
omniauth-twitter
onebox (= 1.8.82)
openid-redis-store
parallel_tests
pg
pry-nav
pry-rails
Expand Down
4 changes: 4 additions & 0 deletions app/models/global_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions config/boot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.