diff --git a/.rspec_parallel b/.rspec_parallel new file mode 100644 index 00000000000..252e250b492 --- /dev/null +++ b/.rspec_parallel @@ -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 diff --git a/Gemfile b/Gemfile index 525fa178017..0ab63546485 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 08fcda1a031..322daf1f2c6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/app/models/global_setting.rb b/app/models/global_setting.rb index 67320ee5e8c..56abedade9a 100644 --- a/app/models/global_setting.rb +++ b/app/models/global_setting.rb @@ -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 diff --git a/config/boot.rb b/config/boot.rb index 97806eac15a..fdf031f52fe 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -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