Class: ParallelTests
- Inherits:
-
Object
show all
- Defined in:
- lib/parallel_tests.rb,
lib/parallel_tests/grouper.rb,
lib/parallel_tests/railtie.rb
Defined Under Namespace
Classes: Grouper, Railtie, RuntimeLogger
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
44
45
46
47
48
49
50
|
# File 'lib/parallel_tests.rb', line 44
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
52
53
54
55
56
57
58
|
# File 'lib/parallel_tests.rb', line 52
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
24
25
|
# File 'lib/parallel_tests.rb', line 9
def self.parse_rake_args(args)
args = [args[:count], args[:pattern], args[:options]]
count = args.shift if args.first.to_s =~ /^\d*$/
num_processes = count.to_i unless count.to_s.empty?
num_processes ||= ENV['PARALLEL_TEST_PROCESSORS'].to_i if ENV['PARALLEL_TEST_PROCESSORS']
num_processes ||= Parallel.processor_count
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
38
39
40
41
42
|
# File 'lib/parallel_tests.rb', line 38
def self.run_tests(test_files, process_number, options)
require_list = test_files.map { |filename| %{"#{File.expand_path filename}"} }.join(",")
cmd = "ruby -Itest -e '[#{require_list}].each {|f| require f }' -- #{options[:test_options]}"
execute_command(cmd, process_number, options)
end
|
.runtime_log ⇒ Object
64
65
66
|
# File 'lib/parallel_tests.rb', line 64
def self.runtime_log
'tmp/parallel_runtime_test.log'
end
|
.summarize_results(results) ⇒ Object
68
69
70
71
72
73
74
75
76
|
# File 'lib/parallel_tests.rb', line 68
def self.summarize_results(results)
results = results.join(' ').gsub(/s\b/,'') 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
60
61
62
|
# File 'lib/parallel_tests.rb', line 60
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
28
29
30
31
32
33
34
35
36
|
# File 'lib/parallel_tests.rb', line 28
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, options)
end
end
|