Upgrade to Pro — share decks privately, control downloads, hide ads and more …

test-queue makes your tests run fast

test-queue makes your tests run fast

Will Farrington

December 11, 2014

More Decks by Will Farrington

Other Decks in Technology


  1. ANATOMY OF A SCRIPT/TEST-QUEUE #!/usr/bin/env ruby $LOAD_PATH.unshift File.expand_path("./../../rspec", __FILE__) unless

    ENV["TEST_QUEUE_WORKERS"] abort "TEST_QUEUE_WORKERS must be set in env!" end require "test_helper" require "test_queue" require "test_queue/runner/rspec" class CustomTestRunner < TestQueue::Runner::RSpec end CustomTestRunner.new.execute
  2. SETTING UP YOUR AFTER_FORK class RailsRSpecRunner < TestQueue::Runner::RSpec def after_fork(num)

    # ActiveRecord ActiveRecord::Base.configurations["test"]["database"] << num.to_s ActiveRecord::Base.establish_connection(:test) # Redis $redis.client.db = num $redis.client.reconnect end end
  3. SETTING UP YOUR PREPARE class RailsRSpecRunner < TestQueue::Runner::RSpec def prepare(num)

    # grab a copy of your database schema num.times do |i| # load it into a clean copy of your test database end end end
  4. AN EXAMPLE # shared secret export TEST_QUEUE_RELAY_TOKEN=12345 # tell us

    what you're doing export TEST_QUEUE_VERBOSE=1 # create a master test-queue instance TEST_QUEUE_SOCKET= bundle exec rspec-queue # on a server, far, far away... # create a worker that sends results back to the master TEST_QUEUE_RELAY= bundle exec rspec-queue