Rocket Fuelled Cucumbers Joseph Wilk
Dealing with an Outbreak of Cucumbers Joseph Wilk
No Cucumbers where harmed in the making of this presentation. Just mildly shaken up
Scenario : Happy Railsconf attendees Given you have a vague idea what Cucumber is When Joseph completes his presentation Then you should understand the scaling choices And you should feel better prepared to face them
Cucumber Feature: Filling Cucumbers with • BDD framework rocket fuel • Plaintext Scenario: Rocket fuel Given I have trained monkeys • Promotes When I click the launch button communication Then the monkeys should not die Given /^I have trained monkeys$/ do @test_pilots << Monkeys.new end
Cucumber provides the venue Your code makes it slow Shame on you
What are Acceptance Tests? • Customer -facing • Cut through the whole stack • Examples of how the system is intended to be used
You made me Cuke
1 minute ~ build
Local builds 1 minute ~ build
Local builds Autotest 1 minute ~ build
Local builds Autotest Growl 1 minute ~ build
Don’t Panic
Slow testing problems Running all the Cukes takes too long! Development is slowed down by the time to run focused Cukes
Types of Feedback + Speed Development - Confidence Speed Test Build - Confidence +
Happiness is a 10 min build time
Slow builds are the enemy of continuous integration
D evelopment F eedback Its too slow to run the cukes. Just push the code and run away
Reuse - Spork $ spork cucumber $ cucumber --drb require 'rubygems' require 'spork' Spork.prefork do puts "I'm loading all the heavy stuff..." end Spork.each_run do puts "I'm loading the stuff just for this run..." # Cucumber hooks must go here end git://github.com/timcharper/spork.git
Slow services • Search Before('@solr') do • Solr Solr.boot unless Solr.running? • Sphinx end • Databases • Mongo Feature: Searching • Redis @solr • Mysql Scenario: Indexed search • Given ... Message Queues When ... • RabbitMQ Then ...
Run Just Enough Tests Autotest # * Test files must be stored in test/ # * Test files names must start with test_ # * Test class names must start with Test # * Implementation files must be stored in lib/ # * Implementation files must match up with a # test file named # test_.*implementation.rb Cucover @analyzer = Rcov::CodeCoverageAnalyzer.new
http://vimeo.com/12500864
Slicing Features @media, @public Feature: Visitor views artist’s media @feed, @admin Feature: Logged in user views views their activity feed Tagging $ cucumber --tags @media Filenames $ cucumber visitor_* Subsystems $ cucumber features/admin/* Profiles $ cucumber --profile admin
Just enough Database
Just enough Database INSERT INTO `cities` (`name`) VALUES ('Test name') SELECT * FROM `cities` INSERT INTO `venues` ... WHERE (`cities`.`id` = 105838) SELECT * FROM Cache city data `venues` WHERE ... Cache venue data
Test Build Feedback Commit code Have a 1 hour nap
Options • Hardware • Intelligent test selection • Tighter focused tests • Divide and Conquer
Testjour Songkick.com 254 Features, 1257 scenarios, 10807 steps 1 build server ~ 4 hours 5 build servers ~ 2 hours
120 sad minutes of my life...
$ git clone git://github.com/brynary/testjour.git $ rake gem install $ testjour --help
$ git clone git://github.com/brynary/testjour.git $ rake gem install $ testjour --help testjour help:
Testjour Worker Slave Worker Redis Worker Work Master Slave Queue Worker Worker Slave Worker
Testjour Worker rsync - code Slave Worker Redis Worker Work Master Slave Queue Worker Worker rsync - code Slave Worker
Testjour Worker rsync - code Slave Worker Redis Worker Work Master Slave Queue Worker Worker rsync - code Slave Worker
Testjour Worker rsync - code Slave Worker Redis Worker Work Master Slave Queue Worker Worker rsync - code Slave Worker
Looking to the Cloud EC2, Rackspace Cloud, Windows Azure
Looking to the Cloud EC2, Rackspace Cloud, Windows Azure 1 build server ~ 4 hours
Looking to the Cloud EC2, Rackspace Cloud, Windows Azure 1 build server ~ 4 hours 20 build servers ~ 11:40 minutes
Looking to the Cloud EC2, Rackspace Cloud, Windows Azure 1 build server ~ 4 hours 20 build servers ~ 11:40 minutes $2068.99 / $3000
Ec2 Disc image AMI slim-sumo
Ec2 Disc image AMI Launch slim-sumo
Ec2 Disc image ec2 ec2 ec2 ec2 AMI node node node node Launch slim-sumo
Ec2 Disc image ec2 ec2 ec2 ec2 AMI node node node node Launch Build ENV['EC2_URL'] = ec2_url require 'slim-sumo' Sumo.new.running.map{|ec2_node| ec2_node[:hostname]} slim-sumo
http://vimeo.com/12467100
require 'rubygems' require 'hydra' require 'hydra/tasks' Hydra::TestTask.new('hydra') do |t| t.add_files 'features/**/*.feature' t.verbose = false t.autosort = false end
“Buy lots of hardware”
“Buy lots of hardware” “more hardware please”
“Buy lots of hardware” “more hardware please” “Just a little bit more hardware”
“Buy lots of hardware” “more hardware please” “Just a little bit more hardware”
Just run the tests that matter...
Failure probability matters European Computing manufacturer
Failure probability matters European Computing manufacturer Automated test suite ~ 18 hours
Failure probability matters European Computing manufacturer Automated test suite ~ 18 hours Tests that were most ~ 2 hours likely to fail
http://vimeo.com/12467122
Tests that never fail
Tests that never fail
Tests which Tests that regularly fail never fail
Tests which Tests that regularly fail never fail Daily Build
Tests which Tests that regularly fail never fail Daily Build Nightly Build
Tests which Tests that regularly fail never fail Daily Build Nightly Build $cucumber --tags ~@nightly $cucumber --tags @nightly
Flickering Confidence
Flickering Confidence FAIL
Flickering Confidence FAIL FAIL
Flickering Confidence FAIL FAIL PASS
Flickering Confidence FAIL FAIL PASS Main Flicker @flicker
Divide and conquer 7 7 7 1 hour 7 7 7 7 7 7 • Rails - Engines • Service Orientated Architecture
Divide and Concuquer
Divide and Concuquer
Divide and Concuquer
Divide and Concuquer
Divide and Concuquer
Divide and Concuquer Scenario : Related artists Given an artist “SYGC” And “M.Bison” is related to “SYGC” When I visit the artist Then I should see within Similar Artists a link to “M.Bison”
Divide and conquer Rails Scenario : Related artists Given an artist “SYGC” And “M.Bison” is related to “SYGC” When I visit the artist Then I should see within Similar Artists a link to “M.Bison”
Divide and conquer Related Rails Artists Service Scenario : Related artists Given an artist “SYGC” And “M.Bison” is related to “SYGC” When I visit the artist Then I should see within Similar Artists a link to “M.Bison”
Divide and conquer related(artist) Related Rails Artists Service Scenario : Related artists Given an artist “SYGC” And “M.Bison” is related to “SYGC” When I visit the artist Then I should see within Similar Artists a link to “M.Bison”
Divide and conquer related(artist) Related Rails Artists HTML Service Scenario : Related artists Given an artist “SYGC” And “M.Bison” is related to “SYGC” When I visit the artist Then I should see within Similar Artists a link to “M.Bison”
Divide and conquer related(artist) Related Rails Artists HTML Service Scenario : Related artists Given an artist “SYGC” And “M.Bison” is related to “SYGC” When I visit the artist Then I should see within Similar Artists a link to “M.Bison”
Divide and conquer related(artist) Related Rails Artists HTML Service unit test unit test Scenario : Related artists Given an artist “SYGC” And “M.Bison” is related to “SYGC” When I visit the artist Then I should see within Similar Artists a link to “M.Bison”
Don’t use Acceptance tests http://jamesshore.com/Blog/Alternatives- to-Acceptance-Testing.html Heresy!
Recommend
More recommend