module ParallelTests

rake tasks for Rails 3+

Constants

GREP_PROCESSES_COMMAND
VERSION
WINDOWS

Public Class Methods

bundler_enabled?() click to toggle source

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

# File lib/parallel_tests.rb, line 28
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)
    current, previous = File.expand_path("..", current), current
  end

  false
end
delta() { || ... } click to toggle source
# File lib/parallel_tests.rb, line 68
def delta
  before = now.to_f
  yield
  now.to_f - before
end
determine_number_of_processes(count) click to toggle source
# File lib/parallel_tests.rb, line 19
def determine_number_of_processes(count)
  [
    count,
    ENV["PARALLEL_TEST_PROCESSORS"],
    Parallel.processor_count
  ].detect{|c| not c.to_s.strip.empty? }.to_i
end
first_process?() click to toggle source
# File lib/parallel_tests.rb, line 43
def first_process?
  !ENV["TEST_ENV_NUMBER"] || ENV["TEST_ENV_NUMBER"].to_i == 0
end
now() click to toggle source

real time even if someone messed with timecop in tests

# File lib/parallel_tests.rb, line 60
def now
  if Time.respond_to?(:now_without_mock_time) # Timecop
    Time.now_without_mock_time
  else
    Time.now
  end
end
number_of_running_processes() click to toggle source

Fun fact: this includes the current process if it's run via parallel_tests

# File lib/parallel_tests.rb, line 53
def number_of_running_processes
  result = %x`#{GREP_PROCESSES_COMMAND}`
  raise "Could not grep for processes -> #{result}" if result.strip != "" && !$?.success?
  result.split("\n").size
end
wait_for_other_processes_to_finish() click to toggle source
# File lib/parallel_tests.rb, line 47
def wait_for_other_processes_to_finish
  return unless ENV["TEST_ENV_NUMBER"]
  sleep 1 until number_of_running_processes <= 1
end