Class: ParallelTests::Test::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/parallel_tests/test/runner.rb

Direct Known Subclasses

Cucumber::Runner, RSpec::Runner

Constant Summary collapse

NAME =
'Test'

Class Method Summary collapse

Class Method Details

.execute_command(cmd, process_number, num_processes, options) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/parallel_tests/test/runner.rb', line 51

def execute_command(cmd, process_number,  num_processes, options)
  env = (options[:env] || {}).merge(
    "TEST_ENV_NUMBER" => test_env_number(process_number, options),
    "PARALLEL_TEST_GROUPS" => num_processes
  )
  cmd = "nice #{cmd}" if options[:nice]
  execute_command_and_capture_output(env, cmd, options[:serialize_stdout])
end

.execute_command_and_capture_output(env, cmd, silence) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/parallel_tests/test/runner.rb', line 60

def 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 = open("|#{cmd}", "r") { |output| capture_output(output, silence) }
  exitstatus = $?.exitstatus

  {:stdout => output, :exit_status => exitstatus}
end

.find_results(test_output) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/parallel_tests/test/runner.rb', line 73

def 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

Returns:

  • (Boolean)


33
34
35
# File 'lib/parallel_tests/test/runner.rb', line 33

def line_is_result?(line)
  line =~ /\d+ failure/
end

.nameObject

— usually overwritten by other runners



11
12
13
# File 'lib/parallel_tests/test/runner.rb', line 11

def name
  NAME
end

.run_tests(test_files, process_number, num_processes, options) ⇒ Object



27
28
29
30
31
# File 'lib/parallel_tests/test/runner.rb', line 27

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

.runtime_logObject



15
16
17
# File 'lib/parallel_tests/test/runner.rb', line 15

def runtime_log
  'tmp/parallel_runtime_test.log'
end

.summarize_results(results) ⇒ Object



86
87
88
89
# File 'lib/parallel_tests/test/runner.rb', line 86

def 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, options) ⇒ Object



81
82
83
84
# File 'lib/parallel_tests/test/runner.rb', line 81

def test_env_number(process_number, options)
  n = options[:advance_number].to_i + process_number + 1
  n == 0 ? '' : n
end

.test_file_nameObject



23
24
25
# File 'lib/parallel_tests/test/runner.rb', line 23

def test_file_name
  "test"
end

.test_suffixObject



19
20
21
# File 'lib/parallel_tests/test/runner.rb', line 19

def test_suffix
  "_test.rb"
end

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

finds all tests and partitions them into groups



40
41
42
43
44
45
46
47
48
49
# File 'lib/parallel_tests/test/runner.rb', line 40

def tests_in_groups(tests, num_groups, options={})
  tests = find_tests(tests, options)

  tests = if options[:group_by] == :found
    tests.map { |t| [t, 1] }
  else
    with_runtime_info(tests)
  end
  Grouper.in_even_groups_by_size(tests, num_groups, options)
end