Top Banner
Continuous Deployment in Perl Presentation by Alex Balhatchet (KAORU)
32

Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

Jun 03, 2015

Download

Documents

Alex Balhatchet

What is continuous deployment?

What are the challenges to getting it right?

How does Perl meet/destroy those challenges?
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

Continuous Deployment in PerlPresentation by Alex Balhatchet (KAORU)

Page 2: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

Intro

Page 3: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

What is continuous deployment?

Commit Changes

Test Changes

Deploy Changes As quickly as possible! :-)

Page 4: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

Committing Changes

● Use your favourite VCS

● Push the changes somewhere centralized (staging/testing environment)

● This should kick off a "build and test" cycle if one is not currently running

Page 5: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

Testing Changes

Perl is absolutely fantastic for testing.

● TAP

● TAP::Harness / App::Prove

● Test::Builder / Test::More

Page 6: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

Deploying Changes

● Pick your favourite deployment method

● Make it as fast as possible

● Make it as easy as possible

Page 7: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

Challenges

● Fast tests

● Reliable tests

● Fast deployment

Page 8: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

Challenges

● Fast tests

● Reliable tests

● Fast deployment

Focus of this talk

Page 9: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

Perl Testing

Page 10: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

TAP::Harness and App::Prove

Page 11: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

TAP::Harness and App::Prove

/usr/bin/prove

uses App::Prove

uses TAP::Harness

Page 12: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

App::Prove features - basics

● Run lots of tests with one command

● Hide non-failure output

● Run tests in parallel

● Show timing information

Page 13: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

App::Prove features - basics

alex@karin$ prove -l -r -j 16 t/t/00-load.t .......... ok t/01-backup.t ........ ok t/02-delete_files.t .. ok All tests successful.Files=3, Tests=51, 1 wallclock secs ( 0.06 usr 0.01 sys + 0.78 cusr 0.20 csys = 1.05 CPU)Result: PASS

Page 14: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

App::Prove features - advanced

● Load plugins from App::Prove::Plugin::*

● Save the TAP results to a .tgz archive

● Save state between runs and use that state to change the order for future runs

Page 15: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

App::Prove features - advancedalex@karin$ prove -l -r --state=hot,all,save t/No saved state, selection will be emptyt/00-load.t .. okt/01-good.t .. okt/02-bad.t ... 1/1

alex@karin$ prove -l -r --state=hot,all,save t/t/02-bad.t ... 1/1 <===== Runs first!t/00-load.t .. okt/01-good.t .. ok

Page 16: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

App::Prove features - advanced

Other "state" options:

● slow - very useful with -j N

● fresh - only run the tests you need to

● last - same as last run, even with --shuffle

Page 17: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

Test::Aggregate

Page 18: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

Test::Aggregate

● Combine multiple .t files into a single file

● Avoids compilation overhead

● Therefore speeds up your tests!

Page 19: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

Test::Aggregate::Nested

● Alpha code

● Uses the fairly recently added syntax for subtests in TAP

● Works really well for us!

Page 20: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

Test::Aggregate caveats

● Breaks BEGIN and END blocks

(use Scope::Guard instead!)

● exit() is also a bad idea!

● Be aware of Test modules which use these

(Test::NoWarnings is the most common!)

Page 21: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

Parallelisation of Aggregated Tests

Currently closed source - sorry! The logic is:

i. Split up tests into N groups

ii. Copy .t files into temporary directory

iii. Write temporary .t file that uses Test::Aggregate::Nested

iv. Run those tests with prove -j N

Page 22: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

TAP::Harness::Archive

Page 23: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

TAP::Harness::Archive

● "isa" TAP::Harness

● Stores the TAP output in a tar archive

● Gives you full TAP even when running in parallel

● Allows you to run your tests once and then format the results in multiple ways

Page 24: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

How we format our TAP

● Process the output from our parallelised aggregated test runs

● Match up the failures with the .t files

● Write a summary in Markdown format that's later converted to HTML and emailed to us

Page 25: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

How you might format your TAP

● TAP::Formatter::JUnit (eg. for Jenkins)

● TAP::Formatter::TeamCity

● TAP::Formatter::HTML

Page 26: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

TAP::Formatter::HTML example

Page 27: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

TAP::Formatter::HTML example

Page 28: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

Putting it all together

Page 29: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

Continuous Deployment at Lokku

svn commit

Perl daemon notices commit

Parallelised and aggregated test run starts running

Nicely formatted results are emailed on success or failure

On test success new code is automatically pushed

Deployment is one command and very quick

Page 30: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

What's next?

Page 31: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

What's next?

● Test::WWW::Selenium::More

● Faster tests - more unit tests, fewer integration tests

● Parallelised deployment

Page 32: Continuous testing and deployment in Perl (London.pm Technical Meeting October 2012)

Any questions?

Thanks!