Module: ParallelTests::Tasks
- Defined in:
- lib/parallel_tests/tasks.rb
Class Method Summary collapse
- .check_for_pending_migrations ⇒ Object
-
.parse_args(args) ⇒ Object
parallel:spec[:count, :pattern, :options].
- .rails_env ⇒ 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 chaning the exit-status normally I’d not do this, but it has been lots of fun and a great learning experience :).
Class Method Details
.check_for_pending_migrations ⇒ Object
41 42 43 44 45 46 |
# File 'lib/parallel_tests/tasks.rb', line 41 def check_for_pending_migrations abort_migrations = "db:abort_if_pending_migrations" if Rake::Task.task_defined?(abort_migrations) Rake::Task[abort_migrations].invoke end end |
.parse_args(args) ⇒ Object
parallel:spec[:count, :pattern, :options]
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/parallel_tests/tasks.rb', line 49 def parse_args(args) # order as given by user args = [args[:count], args[:pattern], args[:options]] # 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 [num_processes, pattern.to_s, .to_s] end |
.rails_env ⇒ Object
6 7 8 |
# File 'lib/parallel_tests/tasks.rb', line 6 def rails_env ENV['RAILS_ENV'] || 'test' end |
.run_in_parallel(cmd, options = {}) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/parallel_tests/tasks.rb', line 10 def run_in_parallel(cmd, ={}) count = " -n #{[:count]}" if [:count] executable = File.("../../../bin/parallel_test", __FILE__) command = "#{executable} --exec '#{cmd}'#{count}#{' --non-parallel' if [:non_parallel]}" command << " --advance-number #{[:advance_number]}" if [:advance_number] 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 chaning 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
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/parallel_tests/tasks.rb', line 30 def suppress_output(command, ignore_regex) activate_pipefail = "set -o pipefail" remove_ignored_lines = %Q{(grep -v "#{ignore_regex}" || test 1)} if system("#{activate_pipefail} && test 1") "#{activate_pipefail} && (#{command}) | #{remove_ignored_lines}" else command end end |