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
Tweet

More Decks by Will Farrington

Other Decks in Technology

Transcript

  1. makes your
    TESTS

    View full-size slide

  2. tmm1/test-queue

    View full-size slide

  3. DISTRIBUTE THE LOAD

    View full-size slide

  4. WITH CORES
    USE THEM IF YOU
    HAVE THEM

    View full-size slide

  5. BRING YOUR OWN

    View full-size slide

  6. USE SOMEONE ELSE'S

    View full-size slide

  7. THERE ARE SO MANY
    CLOUDS OUT THERE

    View full-size slide

  8. WHICH CLOUD?

    View full-size slide

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

    View full-size slide

  10. BUT NO, REALLY, HOW?

    View full-size slide

  11. 1. TAKE A SOCKET

    View full-size slide

  12. 2. FORK SOME
    WORKERS

    View full-size slide

  13. 3. SMARTLY
    DISTRIBUTE TESTS

    View full-size slide

  14. 4. SPEND LESS TIME
    WAITING ON CI

    View full-size slide

  15. 5. SPEND MORE TIME
    SHIPPING CODE

    View full-size slide

  16. GETTING STARTED

    View full-size slide

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

    View full-size slide

  18. 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

    View full-size slide

  19. 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

    View full-size slide

  20. 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

    View full-size slide

  21. ADVANCED USAGE
    AT A HIGH LEVEL

    View full-size slide

  22. REMOTE WORKERS

    View full-size slide

  23. 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

    View full-size slide

  24. COMBINE WITH YOUR
    CI SYSTEM

    View full-size slide

  25. RUN YOUR TESTS
    FASTER

    View full-size slide

  26. THANKS
    I AM @WFARR

    View full-size slide

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

    View full-size slide