update parallel_testing task

pull/6731/head
Jens Ulferts 6 years ago
parent 22de96411f
commit 1c4571180c
No known key found for this signature in database
GPG Key ID: 3CAA4B1182CF5308
  1. 40
      .travis.yml
  2. 173
      lib/tasks/parallel_testing.rake
  3. 17
      script/ci/runner.sh
  4. 10
      script/ci/setup.sh

@ -99,46 +99,38 @@ jobs:
script:
- bash script/ci/setup.sh spec_legacy postgres
- bash script/ci/runner.sh spec_legacy 1 1
- name: 'cucumber (1/1) - mysql'
script:
- bash script/ci/setup.sh cucumber mysql
- bash script/ci/runner.sh cucumber 1 1
- name: 'cucumber (1/1) - postgresql'
script:
- bash script/ci/setup.sh cucumber postgres
- bash script/ci/runner.sh cucumber 1 1
- name: 'unit specs (1/4) - mysql'
script:
- bash script/ci/setup.sh specs mysql
- bash script/ci/runner.sh specs 4 1
- bash script/ci/setup.sh units mysql
- bash script/ci/runner.sh units 4 1
- name: 'unit specs (1/4) - postgresql'
script:
- bash script/ci/setup.sh specs postgres
- bash script/ci/runner.sh specs 4 1
- bash script/ci/setup.sh units postgres
- bash script/ci/runner.sh units 4 1
- name: 'unit specs (2/4) - mysql'
script:
- bash script/ci/setup.sh specs mysql
- bash script/ci/runner.sh specs 4 2
- bash script/ci/setup.sh units mysql
- bash script/ci/runner.sh units 4 2
- name: 'unit specs (2/4) - postgresql'
script:
- bash script/ci/setup.sh spec postgres
- bash script/ci/runner.sh specs 4 2
- bash script/ci/setup.sh units postgres
- bash script/ci/runner.sh units 4 2
- name: 'unit specs (3/4) - mysql'
script:
- bash script/ci/setup.sh specs mysql
- bash script/ci/runner.sh specs 4 3
- bash script/ci/setup.sh units mysql
- bash script/ci/runner.sh units 4 3
- name: 'unit specs (3/4) - postgresql'
script:
- bash script/ci/setup.sh specs postgres
- bash script/ci/runner.sh specs 4 3
- bash script/ci/setup.sh units postgres
- bash script/ci/runner.sh units 4 3
- name: 'unit specs (4/4) - mysql'
script:
- bash script/ci/setup.sh specs mysql
- bash script/ci/runner.sh specs 4 4
- bash script/ci/setup.sh units mysql
- bash script/ci/runner.sh units 4 4
- name: 'unit specs (4/4) - postgresql'
script:
- bash script/ci/setup.sh specs postgres
- bash script/ci/runner.sh specs 4 4
- bash script/ci/setup.sh units postgres
- bash script/ci/runner.sh units 4 4
- name: 'feature specs (1/4) - mysql'
script:
- bash script/ci/setup.sh features mysql

@ -27,12 +27,66 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
require 'optparse'
require 'plugins/load_path_helper'
def check_for_pending_migrations
require 'parallel_tests/tasks'
ParallelTests::Tasks.check_for_pending_migrations
end
namespace :parallel do
class ParallelParser
def self.with_args(args, allow_seed = true)
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: rails #{args[0]} -- [options]"
opts.on("-n ARG", "--group-number ARG", Integer) { |num_cpus| options[:num_cpus] = num_cpus || ENV['GROUP'] }
opts.on("-o ARG", "--only-group ARG", Integer) { |group_number| options[:group] = group_number || ENV['GROUP_SIZE'] }
opts.on("-s ARG", "--seed ARG", Integer) { |seed| options[:seed] = seed || ENV['CI_SEED'] } if allow_seed
end.parse!(args[2..-1])
yield options
end
end
def group_option_string(parsed_options)
group_options = parsed_options ? "-n #{parsed_options[:num_cpus]}" : ''
group_options += " --only-group #{parsed_options[:group]}" if parsed_options[:group]
group_options
end
def run_specs(parsed_options, folders, pattern = '', additional_options: nil)
check_for_pending_migrations
group_options = group_option_string(parsed_options)
rspec_options = ''
if parsed_options[:seed]
rspec_options += "--seed #{parsed_options[:seed]}"
end
if additional_options
rspec_options += " #{additional_options}"
end
group_options += " -o '#{rspec_options}'" if rspec_options.length.positive?
sh "bundle exec parallel_test --type rspec #{group_options} #{folders} #{pattern}"
end
def run_cukes(parsed_options, folders)
exit 'No feature folders to run cucumber on' if folders.blank?
group_options = group_option_string(parsed_options)
support_files = ([Rails.root.join('features').to_s] + Plugins::LoadPathHelper.cucumber_load_paths)
.map { |path| ['-r', Shellwords.escape(path)] }.flatten.join(' ')
cucumber_options = "-o ' -p rerun #{support_files}'"
sh "bundle exec parallel_test --type cucumber #{cucumber_options} #{group_options} #{folders}"
end
desc 'Run all suites in parallel (one after another)'
task all: ['parallel:plugins:specs',
'parallel:plugins:features',
@ -47,103 +101,90 @@ namespace :parallel do
'parallel:plugins:features',
'parallel:plugins:cucumber']
def run_specs(pattern)
check_for_pending_migrations
desc 'Run plugin specs in parallel'
task specs: [:environment] do
spec_folders = Plugins::LoadPathHelper.spec_load_paths.join(' ')
num_cpus = ENV['GROUP_SIZE']
group = ENV['GROUP']
ParallelParser.with_args(ARGV) do |options|
ARGV.each { |a| task(a.to_sym) {} }
group_options = num_cpus ? "-n #{num_cpus}" : ''
group_options += " --only-group #{group}" if group
run_specs options, spec_folders
end
end
spec_folders = Plugins::LoadPathHelper.spec_load_paths.join(' ')
desc 'Run plugin unit specs in parallel'
task units: [:environment] do
pattern = "--pattern '^spec/(?!features\/)'"
sh "bundle exec parallel_test --type rspec #{group_options} #{spec_folders} #{pattern}"
end
spec_folders = Plugins::LoadPathHelper.spec_load_paths.join(' ')
desc 'Run plugin specs (non features) in parallel'
task specs: [:environment] do
pattern = "--pattern '.+/spec/(?!features\/)'"
ParallelParser.with_args(ARGV) do |options|
ARGV.each { |a| task(a.to_sym) {} }
run_specs pattern
run_specs options, spec_folders, pattern
end
end
desc 'Run plugin feature specs in parallel'
task features: [:environment] do
pattern = "--pattern '.+/spec/features/'"
pattern = "--pattern '^spec\/features\/'"
run_specs pattern
spec_folders = Plugins::LoadPathHelper.spec_load_paths.join(' ')
ParallelParser.with_args(ARGV) do |options|
ARGV.each { |a| task(a.to_sym) {} }
run_specs options, spec_folders, pattern
end
end
desc 'Run plugin cucumber features in parallel'
task cucumber: [:environment] do
check_for_pending_migrations
num_cpus = ENV['GROUP_SIZE']
group = ENV['GROUP']
group_options = num_cpus ? "-n #{num_cpus}" : ''
group_options += " --only-group #{group}" if group
support_files = [Rails.root.join('features').to_s] + Plugins::LoadPathHelper.cucumber_load_paths
support_files = support_files.map { |path|
['-r', Shellwords.escape(path)]
}.flatten.join(' ')
ParallelParser.with_args(ARGV) do |options|
ARGV.each { |a| task(a.to_sym) {} }
feature_folders = Plugins::LoadPathHelper.cucumber_load_paths.join(' ')
cucumber_options = "-o ' -p rerun #{support_files}'"
sh "bundle exec parallel_test --type cucumber #{cucumber_options} #{group_options} #{feature_folders}"
run_cukes(options, feature_folders)
end
end
end
desc 'Run legacy specs in parallel'
task :spec_legacy do
check_for_pending_migrations
num_cpus = ENV['GROUP_SIZE']
group = ENV['GROUP']
seed = ENV['CI_SEED']
ParallelParser.with_args(ARGV) do |options|
ARGV.each { |a| task(a.to_sym) {} }
spec_options = num_cpus ? "-n #{num_cpus}" : ''
spec_options += " --only-group #{group}" if group
spec_options += " -o '--seed #{seed}'" if seed
sh "bundle exec parallel_test --type rspec -o '-I spec_legacy' #{spec_options} spec_legacy"
run_specs options, 'spec_legacy', '', additional_options: '-I spec_legacy'
end
end
desc 'Run cucumber features in parallel (custom task)'
task :cucumber do
check_for_pending_migrations
num_cpus = ENV['GROUP_SIZE']
group = ENV['GROUP']
desc 'Run spec in parallel (custom task)'
task :specs do
ParallelParser.with_args(ARGV) do |options|
ARGV.each { |a| task(a.to_sym) {} }
group_options = num_cpus ? "-n #{num_cpus}" : ''
group_options += " --only-group #{group}" if group
run_specs options, 'spec'
end
end
support_files = [Rails.root.join('features').to_s] + Plugins::LoadPathHelper.cucumber_load_paths
support_files = support_files.map { |path|
['-r', Shellwords.escape(path)]
}.flatten.join(' ')
desc 'Run feature specs in parallel'
task features: [:environment] do
pattern = "--pattern '^spec\/features\/'"
cucumber_options = "-o ' -p rerun #{support_files}'"
ParallelParser.with_args(ARGV) do |options|
ARGV.each { |a| task(a.to_sym) {} }
sh "bundle exec parallel_test --type cucumber #{cucumber_options} #{group_options} features"
run_specs options, 'spec', pattern
end
end
desc 'Run rspec in parallel (custom task)'
task :rspec do
check_for_pending_migrations
num_cpus = ENV['GROUP_SIZE']
group = ENV['GROUP']
seed = ENV['CI_SEED']
desc 'Run unit specs in parallel'
task units: [:environment] do
pattern = "--pattern '^spec/(?!features\/)'"
spec_options = num_cpus ? "-n #{num_cpus}" : ''
spec_options += " --only-group #{group}" if group
spec_options += " -o '--seed #{seed}'" if seed
ParallelParser.with_args(ARGV) do |options|
ARGV.each { |a| task(a.to_sym) {} }
sh "bundle exec parallel_test --type rspec #{spec_options} spec"
run_specs options, 'spec', pattern
end
end
end

@ -47,20 +47,9 @@ case "$1" in
npm)
npm test
;;
spec_legacy)
echo "Preparing SCM test repositories for legacy specs"
bundle exec rake test:scm:setup:all
exec bundle exec rspec -I spec_legacy -o "--seed $CI_SEED" spec_legacy
;;
specs)
bin/parallel_test --type rspec -o "--seed $CI_SEED" -n $2 --only-group $3 --pattern '^spec/(?!features\/)' spec
;;
features)
bin/parallel_test --type rspec -o "--seed $CI_SEED" -n $2 --only-group $3 --pattern '^spec\/features\/' spec
;;
cucumber)
bin/parallel_test --type cucumber -n $2 --only-group $3 features
plugins:cucumber)
bundle exec rake parallel:$1 -- --group-number $2 --only-group $3
;;
*)
bundle exec rake parallel:$1
bundle exec rake parallel:$1 -- --group-number $2 --only-group $3 --seed $CI_SEED
esac

@ -60,10 +60,14 @@ if [ $1 = 'npm' ]; then
echo "No asset compilation required"
fi
if [ $1 = 'specs' ]; then
if [ $1 = 'units' ]; then
# Install pandoc for testing textile migration
run "travis_retry sudo apt-get update -qq"
run "travis_retry sudo apt-get install -qq pandoc"
run "sudo apt-get update -qq"
run "sudo apt-get install -qq pandoc"
fi
if [ $1 = 'spec_legacy' ]; then
run "bundle exec rake test:scm:setup:all"
fi
run "cp -rp public/assets/frontend_assets.manifest.json config/frontend_assets.manifest.json"

Loading…
Cancel
Save