Module: ParallelTests::Tasks
- Defined in:
- lib/parallel_tests/tasks.rb
Class Method Summary collapse
- .check_for_pending_migrations ⇒ Object
- .load_lib ⇒ Object
-
.parse_args(args) ⇒ Object
parallel:spec[:count, :pattern, :options, :pass_through].
- .purge_before_load ⇒ Object
- .rails_env ⇒ Object
- .rake_bin ⇒ Object
- .run_in_parallel(cmd, options = {}) ⇒ Object
-
.suppress_output(command, ignore_regex) ⇒ Object
this is a crazy-complex solution for a very simple problem: removing certain lines from the output without changing the exit-status normally I'd not do this, but it has been lots of fun and a great learning experience :).
- .suppress_schema_load_output(command) ⇒ Object
Class Method Details
.check_for_pending_migrations ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/parallel_tests/tasks.rb', line 68 def check_for_pending_migrations ["db:abort_if_pending_migrations", "app:db:abort_if_pending_migrations"].each do |abort_migrations| if Rake::Task.task_defined?(abort_migrations) Rake::Task[abort_migrations].invoke break end end end |
.load_lib ⇒ Object
19 20 21 22 |
# File 'lib/parallel_tests/tasks.rb', line 19 def load_lib $LOAD_PATH << File.(File.join(File.dirname(__FILE__), '..')) require "parallel_tests" end |
.parse_args(args) ⇒ Object
parallel:spec[:count, :pattern, :options, :pass_through]
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/parallel_tests/tasks.rb', line 78 def parse_args(args) # order as given by user args = [args[:count], args[:pattern], args[:options], args[:pass_through]] # count given or empty ? # parallel:spec[2,models,options] # parallel:spec[,models,options] count = args.shift if args.first.to_s =~ /^\d*$/ num_processes = count.to_i unless count.to_s.empty? pattern = args.shift = args.shift pass_through = args.shift [num_processes, pattern.to_s, .to_s, pass_through.to_s] end |
.purge_before_load ⇒ Object
24 25 26 27 28 |
# File 'lib/parallel_tests/tasks.rb', line 24 def purge_before_load if Gem::Version.new(Rails.version) > Gem::Version.new('4.2.0') Rake::Task.task_defined?('db:purge') ? 'db:purge' : 'app:db:purge' end end |
.rails_env ⇒ Object
7 8 9 |
# File 'lib/parallel_tests/tasks.rb', line 7 def rails_env 'test' end |
.rake_bin ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/parallel_tests/tasks.rb', line 11 def rake_bin # Prevent 'Exec format error' Errno::ENOEXEC on Windows return "rake" if RUBY_PLATFORM =~ /mswin|mingw|cygwin/ binstub_path = File.join('bin', 'rake') return binstub_path if File.exist?(binstub_path) "rake" end |
.run_in_parallel(cmd, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/parallel_tests/tasks.rb', line 30 def run_in_parallel(cmd, ={}) load_lib count = " -n #{[:count]}" unless [:count].to_s.empty? # Using the relative path to find the binary allow to run a specific version of it executable = File.("../../../bin/parallel_test", __FILE__) command = "#{ParallelTests.with_ruby_binary(Shellwords.escape(executable))} --exec '#{cmd}'#{count}#{' --non-parallel' if [:non_parallel]}" abort unless system(command) end |
.suppress_output(command, ignore_regex) ⇒ Object
this is a crazy-complex solution for a very simple problem: removing certain lines from the output without changing the exit-status normally I'd not do this, but it has been lots of fun and a great learning experience :)
- sed does not support | without -r
- grep changes 0 exitstatus to 1 if nothing matches
- sed changes 1 exitstatus to 0
- pipefail makes pipe fail with exitstatus of first failed command
- pipefail is not supported in (zsh)
- defining a new rake task like silence_schema would force users to load parallel_tests in test env
- do not use ' since run_in_parallel uses them to quote stuff
- simple system "set -o pipefail" returns nil even though set -o pipefail exists with 0
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/parallel_tests/tasks.rb', line 51 def suppress_output(command, ignore_regex) activate_pipefail = "set -o pipefail" remove_ignored_lines = %Q{(grep -v "#{ignore_regex}" || test 1)} if File.executable?('/bin/bash') && system('/bin/bash', '-c', "#{activate_pipefail} 2>/dev/null && test 1") # We need to shell escape single quotes (' becomes '"'"') because # run_in_parallel wraps command in single quotes %Q{/bin/bash -c '"'"'#{activate_pipefail} && (#{command}) | #{remove_ignored_lines}'"'"'} else command end end |
.suppress_schema_load_output(command) ⇒ Object
64 65 66 |
# File 'lib/parallel_tests/tasks.rb', line 64 def suppress_schema_load_output(command) ParallelTests::Tasks.suppress_output(command, "^ ->\\|^-- ") end |