Module: ParallelTests

Defined in:
lib/parallel_tests/railtie.rb,
lib/parallel_tests.rb,
lib/parallel_tests/cli.rb,
lib/parallel_tests/pids.rb,
lib/parallel_tests/tasks.rb,
lib/parallel_tests/grouper.rb,
lib/parallel_tests/version.rb,
lib/parallel_tests/gherkin/io.rb,
lib/parallel_tests/test/runner.rb,
lib/parallel_tests/rspec/runner.rb,
lib/parallel_tests/gherkin/runner.rb,
lib/parallel_tests/spinach/runner.rb,
lib/parallel_tests/cucumber/runner.rb,
lib/parallel_tests/gherkin/listener.rb,
lib/parallel_tests/rspec/logger_base.rb,
lib/parallel_tests/cucumber/scenarios.rb,
lib/parallel_tests/test/runtime_logger.rb,
lib/parallel_tests/gherkin/runtime_logger.rb,
lib/parallel_tests/cucumber/failures_logger.rb,
lib/parallel_tests/cucumber/features_with_steps.rb,
lib/parallel_tests/cucumber/scenario_line_logger.rb

Overview

rake tasks for Rails 3+

Defined Under Namespace

Modules: Cucumber, Gherkin, RSpec, Spinach, Tasks, Test Classes: CLI, Grouper, Pids, Railtie

Constant Summary collapse

WINDOWS =
(RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/)
RUBY_BINARY =
File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
DEFAULT_MULTIPLY_PROCESSES =
1.0
VERSION =
'5.5.0'

Class Method Summary collapse

Class Method Details

.bundler_enabled?Boolean

copied from github.com/carlhuda/bundler Bundler::SharedHelpers#find_gemfile

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/parallel_tests.rb', line 66

def bundler_enabled?
  return true if Object.const_defined?(:Bundler)

  previous = nil
  current = File.expand_path(Dir.pwd)

  until !File.directory?(current) || current == previous
    filename = File.join(current, "Gemfile")
    return true if File.exist?(filename)
    previous = current
    current = File.expand_path("..", current)
  end

  false
end

.deltaObject



111
112
113
114
115
# File 'lib/parallel_tests.rb', line 111

def delta
  before = now.to_f
  yield
  now.to_f - before
end

.determine_multiple(multiple) ⇒ Object



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

def determine_multiple(multiple)
  Float(
    [
      multiple,
      ENV["PARALLEL_TEST_MULTIPLY_PROCESSES"],
      DEFAULT_MULTIPLY_PROCESSES
    ].detect { |c| !c.to_s.strip.empty? }
  )
end

.determine_number_of_processes(count) ⇒ Object

used by external libraries, do not rename or change api



18
19
20
21
22
23
24
25
26
# File 'lib/parallel_tests.rb', line 18

def determine_number_of_processes(count)
  Integer(
    [
      count,
      ENV["PARALLEL_TEST_PROCESSORS"],
      Parallel.processor_count
    ].detect { |c| !c.to_s.strip.empty? }
  )
end

.first_process?Boolean

Returns:

  • (Boolean)


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

def first_process?
  ENV["TEST_ENV_NUMBER"].to_i <= 1
end

.last_process?Boolean

Returns:

  • (Boolean)


86
87
88
89
90
91
92
# File 'lib/parallel_tests.rb', line 86

def last_process?
  current_process_number = ENV['TEST_ENV_NUMBER']
  total_processes = ENV['PARALLEL_TEST_GROUPS']
  return true if current_process_number.nil? && total_processes.nil?
  current_process_number = '1' if current_process_number.nil?
  current_process_number == total_processes
end

.nowObject



107
108
109
# File 'lib/parallel_tests.rb', line 107

def now
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
end

.number_of_running_processesObject



103
104
105
# File 'lib/parallel_tests.rb', line 103

def number_of_running_processes
  pids.count
end

.pid_file_pathObject



55
56
57
# File 'lib/parallel_tests.rb', line 55

def pid_file_path
  ENV.fetch('PARALLEL_PID_FILE')
end

.pidsObject



51
52
53
# File 'lib/parallel_tests.rb', line 51

def pids
  @pids ||= Pids.new(pid_file_path)
end

.stop_all_processesObject



59
60
61
62
63
# File 'lib/parallel_tests.rb', line 59

def stop_all_processes
  pids.all.each { |pid| Process.kill(:INT, pid) }
rescue Errno::ESRCH, Errno::EPERM
  # Process already terminated, do nothing
end

.wait_for_other_processes_to_finishObject



98
99
100
101
# File 'lib/parallel_tests.rb', line 98

def wait_for_other_processes_to_finish
  return unless ENV["TEST_ENV_NUMBER"]
  sleep 1 until number_of_running_processes <= 1
end

.with_pid_fileObject



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

def with_pid_file
  Tempfile.open('parallel_tests-pidfile') do |f|
    ENV['PARALLEL_PID_FILE'] = f.path
    # Pids object should be created before threads will start adding pids to it
    # Otherwise we would have to use Mutex to prevent creation of several instances
    @pids = pids
    yield
  ensure
    ENV['PARALLEL_PID_FILE'] = nil
    @pids = nil
  end
end

.with_ruby_binary(command) ⇒ Object



94
95
96
# File 'lib/parallel_tests.rb', line 94

def with_ruby_binary(command)
  WINDOWS ? [RUBY_BINARY, '--', command] : [command]
end