Class: ParallelTests::Test::Runner
- Inherits:
-
Object
- Object
- ParallelTests::Test::Runner
- Defined in:
- lib/parallel_tests/test/runner.rb
Direct Known Subclasses
Constant Summary collapse
- NAME =
'Test'
Class Method Summary collapse
- .execute_command(cmd, process_number, num_processes, options) ⇒ Object
- .execute_command_and_capture_output(env, cmd, silence) ⇒ Object
- .find_results(test_output) ⇒ Object
- .line_is_result?(line) ⇒ Boolean
-
.name ⇒ Object
— usually overwritten by other runners.
- .run_tests(test_files, process_number, num_processes, options) ⇒ Object
- .runtime_log ⇒ Object
- .summarize_results(results) ⇒ Object
- .test_env_number(process_number) ⇒ Object
- .test_file_name ⇒ Object
- .test_suffix ⇒ Object
-
.tests_in_groups(tests, num_groups, options = {}) ⇒ Object
finds all tests and partitions them into groups.
Class Method Details
.execute_command(cmd, process_number, num_processes, options) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/parallel_tests/test/runner.rb', line 50 def self.execute_command(cmd, process_number, num_processes, ) env = ([:env] || {}).merge( "TEST_ENV_NUMBER" => test_env_number(process_number), "PARALLEL_TEST_GROUPS" => num_processes ) cmd = "nice #{cmd}" if [:nice] execute_command_and_capture_output(env, cmd, [:serialize_stdout]) end |
.execute_command_and_capture_output(env, cmd, silence) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/parallel_tests/test/runner.rb', line 59 def self.execute_command_and_capture_output(env, cmd, silence) # make processes descriptive / visible in ps -ef exports = env.map do |k,v| "#{k}=#{v};export #{k}" end.join(";") cmd = "#{exports};#{cmd}" output, errput, exitstatus = nil if RUBY_VERSION =~ /^1\.8/ open("|#{cmd}", "r") do |output| output, errput = capture_output(output, nil, silence) end exitstatus = $?.exitstatus else Open3.popen3(cmd) do |stdin, stdout, stderr, thread| stdin.close output, errput = capture_output(stdout, stderr, silence) exitstatus = thread.value.exitstatus end end {:stdout => output, :stderr => errput, :exit_status => exitstatus} end |
.find_results(test_output) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/parallel_tests/test/runner.rb', line 83 def self.find_results(test_output) test_output.split("\n").map {|line| line = line.gsub(/\.|F|\*/,'').gsub(/\e\[\d+m/,'') next unless line_is_result?(line) line }.compact end |
.line_is_result?(line) ⇒ Boolean
32 33 34 |
# File 'lib/parallel_tests/test/runner.rb', line 32 def self.line_is_result?(line) line =~ /\d+ failure/ end |
.name ⇒ Object
— usually overwritten by other runners
10 11 12 |
# File 'lib/parallel_tests/test/runner.rb', line 10 def self.name NAME end |
.run_tests(test_files, process_number, num_processes, options) ⇒ Object
26 27 28 29 30 |
# File 'lib/parallel_tests/test/runner.rb', line 26 def self.run_tests(test_files, process_number, num_processes, ) require_list = test_files.map { |filename| %{"#{File. filename}"} }.join(",") cmd = "#{executable} -Itest -e '[#{require_list}].each {|f| require f }' -- #{[:test_options]}" execute_command(cmd, process_number, num_processes, ) end |
.runtime_log ⇒ Object
14 15 16 |
# File 'lib/parallel_tests/test/runner.rb', line 14 def self.runtime_log 'tmp/parallel_runtime_test.log' end |
.summarize_results(results) ⇒ Object
95 96 97 98 |
# File 'lib/parallel_tests/test/runner.rb', line 95 def self.summarize_results(results) sums = sum_up_results(results) sums.sort.map{|word, number| "#{number} #{word}#{'s' if number != 1}" }.join(', ') end |
.test_env_number(process_number) ⇒ Object
91 92 93 |
# File 'lib/parallel_tests/test/runner.rb', line 91 def self.test_env_number(process_number) process_number == 0 ? '' : process_number + 1 end |
.test_file_name ⇒ Object
22 23 24 |
# File 'lib/parallel_tests/test/runner.rb', line 22 def self.test_file_name "test" end |
.test_suffix ⇒ Object
18 19 20 |
# File 'lib/parallel_tests/test/runner.rb', line 18 def self.test_suffix "_test.rb" end |
.tests_in_groups(tests, num_groups, options = {}) ⇒ Object
finds all tests and partitions them into groups
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/parallel_tests/test/runner.rb', line 39 def self.tests_in_groups(tests, num_groups, ={}) tests = find_tests(tests, ) tests = if [:group_by] == :found tests.map { |t| [t, 1] } else with_runtime_info(tests) end Grouper.in_even_groups_by_size(tests, num_groups, ) end |