Skip to content
Urban Hafner edited this page May 15, 2013 · 70 revisions

Getting stuff running

With sphinx -- by ujh

At file config/sphinx.yml in the test section:

test:
  mysql41: <%= 9313 + ENV['TEST_ENV_NUMBER'].to_i %>
  indices_location: <%= File.join(Rails.root, "db", "sphinx", "test#{ENV['TEST_ENV_NUMBER']}") %>
  configuration_file: <%= File.join(Rails.root, "config", "test#{ENV['TEST_ENV_NUMBER']}.sphinx.conf")%>
  log: <%= File.join(Rails.root, "log", "test#{ENV['TEST_ENV_NUMBER']}.searchd.log") %>
  query_log: <%= File.join(Rails.root, "log", "test#{ENV['TEST_ENV_NUMBER']}.searchd.query.log") %>
  binlog_path: <%= File.join(Rails.root, "tmp", "binlog", "test#{ENV['TEST_ENV_NUMBER']}") %>
  pid_file: <%= File.join(Rails.root, "tmp", "pids", "test#{ENV['TEST_ENV_NUMBER']}.sphinx.pid") %>

With capybara(~>0.4.0)+selenium -- by rgo

Capybara.server_port = 9887 + ENV['TEST_ENV_NUMBER'].to_i

With capybara(=0.3.9)/Rails 2.3 -- by xunker

Add to features/support/env.rb:

if ENV['TEST_ENV_NUMBER']
  class Capybara::Server
    def find_available_port
      @port = 9887 + ENV['TEST_ENV_NUMBER'].to_i
      @port += 1 while is_port_open?(@port) and not is_running_on_port?(@port)
    end
  end
end

With ci_reporter for rspec -- by morganchristiansson

export CI_REPORTS=results

Add spec/parallel_specs.opts with the contents:

--format progress
--require ci/reporter/rake/rspec_loader
--format CI::Reporter::RSpec:/dev/null

Our project has the following in test/test_helper.rb

if ENV["CI_REPORTS"] == "results"
  require "ci/reporter/rake/test_unit_loader"
end

Run the tasks like this:

rake "parallel:features[,,--format progress --format junit --out ${CI_REPORTS} --no-profile -r features]"

Or without rake like this:

bundle exec $(bundle show parallel_tests)/bin/parallel_test --type features -o '--format progress --format junit --out ${CI_REPORTS} --no-profile -r features'

with .rspec_parallel

Add following to RAILS_ROOT/.rspec_parallel.

--format progress
--require ci/reporter/rake/rspec_loader
--format CI::Reporter::RSpec

Run rake parallel:spec, then rspec generates reports in spec/reports.

For more information on how to configure ci_reporter check under advanced usage on http://caldersphere.rubyforge.org/ci_reporter/

With ci_reporter for test_unit -- by phoet

See this issue 29 for more information:

# add the ci_reporter to create reports for test-runs, since parallel_tests is not invoked through rake
puts "running on #{Socket.gethostname}"
if /buildserver/ =~ Socket.gethostname
  require 'ci/reporter/test_unit'
  module Test
    module Unit
      module UI
        module Console
          class TestRunner
            def create_mediator(suite)
              # swap in ci_reporter custom mediator
              return CI::Reporter::TestUnit.new(suite)
            end
          end
        end
      end
    end
  end
end

With DatabaseCleaner for RSpec -- by sciprog

See issue 66 for more information.

Do not use the truncation strategy in DatabaseCleaner, in your RSpec config.
This strategy seems to cause a bottleneck which will negate any gain made
through parallelization of your tests. If possible, use the transaction strategy
over the truncation strategy.
    *Note: This issue does not seem to exist in relation to features, only to specs.

Features not running in subdirectories

If you have put your features into subdirectories you may have problems running them in parallel as it will not find your step_definitions. To work around this I put all my features into the features directory.

You have to require features/ folder for cucumber in order to load step definitions.

 rake "parallel:features[4, '', '-rfeatures/']"

If you want it to work with rake parallel:features add -rfeatures/ to the end of std_opts in config/cucumber.yml

Disable parallel run for certain cases (cucumber)

If you do not have enough scenarios to warrant a separate instance of external service as described in sphinx section above, create a "mutex" in your env.rb file

Before("@solr") do
  #we do not want solr tests to run in parallel, so let's simulate a mutex
  while File.exists?("tmp/cucumber_solr")
    sleep(0.2)
  end
  File.open("tmp/cucumber_solr", "w") {}
  Sunspot.session = $original_sunspot_session
  Sunspot.remove_all!
  # or do other things
end

After("@solr") do
  File.delete("tmp/cucumber_solr")
end

Fixing "unable to bind to locking port 7054 within 45 seconds ..." error

When running with cucumber + capybara + selenium-webdriver (w firefox), this error may be encountered due to firing of too many firefox instances altogether. To fix this issue, add the following to features/support/env.rb:

unless (env_no = ENV['TEST_ENV_NUMBER'].to_i).zero?
  # As described in the readme
  Capybara.server_port = 8888 + env_no

  # Enforces a sleep time, i need to multiply by 10 to achieve consistent results on
  # my 8 cores vm, may work for less though.
  sleep env_no * 10
end

With action_mailer_cache_delivery (~> 0.3.2) -- by p0deje

You may get unexpected errors like EOFError. If so, make sure cache files differ for processes. Change you config/environment/test.rb

config.action_mailer.cache_settings = { :location => "#{Rails.root}/tmp/cache/action_mailer_cache_delivery#{ENV['TEST_ENV_NUMBER']}.cache" }

With RSpec + Sunspot

It's best to use with sunspot-rails-tester. Then you don't need to run solr with rake task. For this you will only have to update config/sunspot.yml you can make it like this:

test:
  solr:
    hostname: localhost
    port: <%= 8981 + ENV['TEST_ENV_NUMBER'].to_i %>
    log_level: WARNING
    data_path: <%= File.join(::Rails.root, 'solr', 'data', ::Rails.env, ENV['TEST_ENV_NUMBER'].to_i.to_s) %>

With Timecop -- by ledermann

Timecop helps you to test time dependent code, but may cause conflicts with the RuntimeLogger, so measuring process runtime fails. Solution: Make sure that after a spec/test is finished any changes made by Timecop are rolled back. For this, you can use the block syntax (Timecrop.freeze do ... end) or add this to your rspec_helper (if you are using RSpec):

config.after :each do
  Timecop.return
end

Important: Don't use config.before, because this will reset Timecop before the next spec, not right after the current spec - which is too late and confuses parallel_tests.

With TeamCity -- by aaronjensen

TeamCity has its own logger so you'll need to use the --serialize-stdout flag when you run anything in parallel. You'll need to use a custom rake task or script and call parallel_rspec/parallel_test/parallel_cucumber directly.

!! add your own experience / gotchas !!

( ͡° ͜ʖ ͡°) ¯_(ツ)_/¯

Clone this wiki locally