Class: ParallelTests

Inherits:
Object
  • Object
show all
Defined in:
lib/parallel_tests.rb,
lib/parallel_tests/grouper.rb,
lib/parallel_tests/railtie.rb

Direct Known Subclasses

ParallelCucumber, ParallelSpecs

Defined Under Namespace

Classes: Grouper, Railtie

Constant Summary collapse

VERSION =
File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip

Class Method Summary collapse

Class Method Details

.execute_command(cmd, process_number, options) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/parallel_tests.rb', line 42

def self.execute_command(cmd, process_number, options)
  cmd = "TEST_ENV_NUMBER=#{test_env_number(process_number)} ; export TEST_ENV_NUMBER; #{cmd}"
  f = open("|#{cmd}", 'r')
  output = fetch_output(f, options)
  f.close
  {:stdout => output, :exit_status => $?.exitstatus}
end

.find_results(test_output) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/parallel_tests.rb', line 50

def self.find_results(test_output)
  test_output.split("\n").map {|line|
    line = line.gsub(/\.|F|\*/,'')
    next unless line_is_result?(line)
    line
  }.compact
end

.parse_rake_args(args) ⇒ Object

parallel:spec[:count, :pattern, :options]



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/parallel_tests.rb', line 9

def self.parse_rake_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_s.empty? ? Parallel.processor_count : count.to_i)

  pattern = args.shift
  options = args.shift

  [num_processes.to_i, pattern.to_s, options.to_s]
end

.run_tests(test_files, process_number, options) ⇒ Object



36
37
38
39
40
# File 'lib/parallel_tests.rb', line 36

def self.run_tests(test_files, process_number, options)
  require_list = test_files.map { |filename| "\"#{filename}\"" }.join(",")
  cmd = "ruby -Itest -e '[#{require_list}].each {|f| require f }' - #{options[:test_options]}"
  execute_command(cmd, process_number, options)
end

.runtime_logObject



62
63
64
# File 'lib/parallel_tests.rb', line 62

def self.runtime_log
  '__foo__'
end

.summarize_results(results) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/parallel_tests.rb', line 66

def self.summarize_results(results)
  results = results.join(' ').gsub(/s\b/,'') # combine and singularize results
  counts = results.scan(/(\d+) (\w+)/)
  sums = counts.inject(Hash.new(0)) do |sum, (number, word)|
    sum[word] += number.to_i
    sum
  end
  sums.sort.map{|word, number|  "#{number} #{word}#{'s' if number != 1}" }.join(', ')
end

.test_env_number(process_number) ⇒ Object



58
59
60
# File 'lib/parallel_tests.rb', line 58

def self.test_env_number(process_number)
  process_number == 0 ? '' : process_number + 1
end

.tests_in_groups(root, num_groups, options = {}) ⇒ Object

finds all tests and partitions them into groups



26
27
28
29
30
31
32
33
34
# File 'lib/parallel_tests.rb', line 26

def self.tests_in_groups(root, num_groups, options={})
  tests = find_tests(root, options)
  if options[:no_sort] == true
    Grouper.in_groups(tests, num_groups)
  else
    tests = with_runtime_info(tests)
    Grouper.in_even_groups_by_size(tests, num_groups)
  end
end