class Object

Public Instance Methods

parse_task_args(test_tool=:rspec, args) click to toggle source
# File lib/tasks/parallel_testing.rb, line 113
def parse_task_args(test_tool=:rspec, args)
  default = {
    :concurrency => [Sauce::TestBroker.concurrency, 20].min
  }

  if test_tool == :rspec
    default[:test_options] = '-t sauce'
    default[:files] = 'spec'
  end

  if test_tool == :cucumber
    default[:files] = 'features'
  end

  env_args = {
    :concurrency => ENV['concurrency'],
    :features => ENV['features'],
    :parallel_options => ENV['parallel_test_options'],
    :test_options => ENV['test_options'],
    :files => ENV['test_files']
  }

  concurrency = args[:concurrency] || env_args[:concurrency] || default[:concurrency]
  test_options = args[:test_options] || env_args[:test_options] || default[:test_options]
  parallel_options = args[:parallel_options] || env_args[:parallel_options]
  files = args[:files] || env_args[:files] || default[:files]

  return_args = [
    '-n', concurrency.to_s,
    '--type'
  ]

  return_args.push 'saucerspec' if test_tool == :rspec
  return_args.push 'saucecucumber' if test_tool == :cucumber

  if test_options
    return_args.push '-o'
    return_args.push test_options
  end

  return_args.push *(parallel_options.split(' ')) if parallel_options
  return_args.concat files.split

  return return_args
end
run_parallel_tests(t, args, command) click to toggle source
# File lib/tasks/parallel_testing.rb, line 74
def run_parallel_tests(t, args, command)
  skip_check_string = (ENV["SAUCE_SKIP_PARALLEL_CHECKS"] || 'false').downcase
  skip_check = (skip_check_string == 'true')

  warn_of_skipped_parallel_processes if skip_check
  
  if defined? WebMock
    WebMock.disable! if ENV['DISABLE_WEBMOCK_FOR_RAKE'] == 'true'
  end

  if((ParallelTests.number_of_running_processes == 0) || skip_check)
    username    = ENV["SAUCE_USERNAME"].to_s
    access_key  = ENV["SAUCE_ACCESS_KEY"].to_s
    if(!username.empty? && !access_key.empty?)
      parallel_arguments = parse_task_args(command, args)
      ParallelTests::CLI.new.run(parallel_arguments)
    else
      puts <<-ENDLINE
    -----------------------------------------------------------------------
    Your Sauce username and/or access key are unavailable. Please:
    1.  Set the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables.
    2.  Rerun your tests.
    -----------------------------------------------------------------------
      ENDLINE
    end
  else
    puts <<-ENDLINE
  ---------------------------------------------------------------------------
  There are already parallel_tests processes running.  This can interfere
  with test startup and shutdown.

  If you're not running other parallel tests, this might be caused by zombie
  processes (The worst kind of processes).  Kill `em off and try again.
  ---------------------------------------------------------------------------
    ENDLINE
    exit(1)
  end
end
start_tunnel_for_parallel_tests(c) click to toggle source
# File lib/sauce/parallel.rb, line 3
def start_tunnel_for_parallel_tests(c)
  c[:start_tunnel] = ParallelTests.first_process?
  if ParallelTests.first_process?
    at_exit do
      if ParallelTests.first_process?
        ParallelTests.wait_for_other_processes_to_finish
      end
    end
  else
    while not File.exist? "sauce_connect.ready"
      sleep 0.5
    end
  end
end
warn_of_skipped_parallel_processes() click to toggle source
# File lib/tasks/parallel_testing.rb, line 159
def warn_of_skipped_parallel_processes
  puts <<-ENDLINE
  ---------------------------------------------------------------------------
  The SAUCE_SKIP_PARALLEL_CHECKS environment variable is truthy. This will
  cause the gem to run regardless of other parallel_tests processes running,
  and may lead to unexpected behaviour including never ending tests.

  Automatic control of Sauce Connect does NOT work with this option.
  ---------------------------------------------------------------------------
  ENDLINE
end