test-queue makes your tests run fast

test-queue makes your tests run fast

Cd839cc361ffa996be0cc8259f3d7555?s=128

Will Farrington

December 11, 2014
Tweet

Transcript

  1. test-queue

  2. makes your TESTS

  3. RUN FAST

  4. tmm1/test-queue

  5. HOW?

  6. DISTRIBUTE THE LOAD

  7. WITH CORES USE THEM IF YOU HAVE THEM

  8. BRING YOUR OWN

  9. USE SOMEONE ELSE'S

  10. THERE ARE SO MANY CLOUDS OUT THERE

  11. WHICH CLOUD?

  12. PICK ONE I AM NOT HERE TO SELL YOU ANYTHING

  13. BUT NO, REALLY, HOW?

  14. 1. TAKE A SOCKET

  15. 2. FORK SOME WORKERS

  16. 3. SMARTLY DISTRIBUTE TESTS

  17. 4. SPEND LESS TIME WAITING ON CI

  18. 5. SPEND MORE TIME SHIPPING CODE

  19. GETTING STARTED

  20. INSTALL # Gemfile group :test do gem "test-queue" end

  21. 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
  22. 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
  23. 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
  24. DEMO

  25. ADVANCED USAGE AT A HIGH LEVEL

  26. REMOTE WORKERS

  27. 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=1.2.3.4:12345 bundle exec rspec-queue # on a server, far, far away... # create a worker that sends results back to the master TEST_QUEUE_RELAY=1.2.3.4:12345 bundle exec rspec-queue
  28. COMBINE WITH YOUR CI SYSTEM

  29. RUN YOUR TESTS FASTER

  30. THANKS I AM @WFARR

  31. GITHUB.COM/WFARR/SIX_MINUTE_BLOG !⚡ GITHUB.COM/TMM1/TEST-QUEUE