dockercon eu 2015: stop being lazy and test your software!
TRANSCRIPT
The women who programmed the ENIAC to
calculate trajectories periodically checked the
results with a correct, hand-computed table.
working software in production
testingcode reviews
version controlpair programming
high-availability architecture
MotivatorsUpdate application without breaking things!Validate functionality of updatesBe able to trust deployment checks (in CI/CD workflow)Confirm that refactoring didn’t break existing functionality
Why do you skip tests?
45%
15%5%
35% Too slow to run suite 35%Annoying extra step
15%Don’t see the point
5%
Slows down deployment 45%
10
FrustratorsIt takes me an hour to write a single testMy new tests just duplicate existing coverages so there’s no
point (integration overlapping with unit)It takes my test suite over 20 minutes to run, so I don’t run
it locallyTesting distracts me from my normal development workflowSetting up a testing environment is a huge painIt takes too long to deploy when I have a huge test suite
FrustratorsIt takes me an hour to write a single testMy new tests just duplicate existing coverages so there’s no
point (integration overlapping with unit)It takes my test suite over 20 minutes to run, so I don’t run
it locallyTesting distracts me from my normal development workflowSetting up a testing environment is a huge painIt takes too long to deploy when I have a huge test suite
app: build: . command: rails server -p 3000 -b '0.0.0.0'
volumes: - .:/app
ports: - '3000:3000'
links: - postgres
postgres:image: postgres:9.4 ports:
- '5432'
A simple Rails app
app: build: . command: rails server -p 3000 -b '0.0.0.0' volumes:
- .:/app ports:
- '3000:3000'links:
- postgrespostgres:
image: postgres:9.4 ports:
- '5432'
A simple Rails app
app: build: . command: rspec specvolumes:
- .:/app ports:
- '3000:3000'links:
- postgrespostgres:
image: postgres:9.4 ports:
- '5432'
A simple Rails app
docker-compose run -e "RAILS_ENV=test" \ app rake db:setup
docker-compose run -e "RAILS_ENV=test" \ app rspec path/spec.rb
docker-compose up #-d if you wish
Usual Docker Compose development environment
Run rake task to set up db
Then run tests against Docker services
Would you rather…
Find out your code is broken by seeing a failed run of your CI/CD system?
Find out your code is broken by seeing 500s on 500s on 500s in production?
✔
💩
CAUTION!
YMMVSee https://jpetazzo.github.io
- Mixing file systems == bad time- Build cache == bad time
Why do you skip tests?
45%
15%5%
35% Too slow to run suite 35%Annoying extra step
15%Don’t see the point
5%
Slows down deployment 45%
42
But if we change our thinkingto treat containers as just processes, then we can do
some pretty cool stuff.
A syntax similar to Docker Compose forservice definition…
47
web: build: image: my_app dockerfile_path: Dockerfile links: - redis - postgresredis: image: redispostgres: image: postgres
And use it to also define testing steps…
48
- type: parallel steps: - service: demo command: ruby check.rb - service: demo command: rake teaspoon suite=jasmine - service: demo command: rake test
- type: parallel steps:
- service: demo command: ruby check.rb
- service: demo command: rake teaspoon suite-jasmine
- service: demo command: rspec spec
Each step is run independently in a container
49
- service: demo command: ruby check.rb
- service: demo command: rake teaspoon suite-jasmine
- service: demo command: rspec spec
And each container may be located in a range of availability zones
50
Docker makes this possible byproviding the means to create
a predictable, reproducibletesting environment.
—Edsger Dijkstra
“Testing can be a very effective way to show the presence of bugs, but is
hopelessly inadequate for showing their absence.”
54
Resources
Highly recommended talks about development, testing, and lots of interesting stuff: https://speakerdeck.com/searls
Ruby gem for parallel tests: grosser/parallel_testsParallel Docker testing: Jet (from Codeship) CI/CD with Docker: http://pages.codeship.com/dockerRunning commands with Docker Compose: http://
docs.docker.com/composeThe perils of Docker-In-Docker: https://jpetazzo.github.io
This talk: slideshare.net/rheinwein
Thank you!Laura Frank@[email protected]