Hack #68. Run Test Suites Persistently
Speed up your tests.
Large Perl applications with many interconnected modules can take a long time to start up. Perl needs to load, compile, and initialize all of the modules before it can start running your application.
Tests for a large system can be particularly slow. A test suite typically contains lots of small short-lived scripts, each of which pulls in lots of module code at start up. A few seconds of delay per script can add up to a lot of time spent waiting for your test suite to finish.
The cure for long startup times within web-based applications is to run under a persistent environment such as mod_perl
or PersistentPerl. PersistentPerl works for command-line programs as well. It's usually as simple as changing the shebang line from #!/usr/bin/perl to #!/usr/bin/perperl.
Running your test suite persistently is slightly more complicated, and doesn't work for every test, but the benefit is a huge speed increase for most of your tests. Running your test suite persistently can speed up your tests by a factor of five on a slow machine.
The Hack
The first step of the hack is to make Test::Builder-based scripts compatible with PersistentPerl. There are several parts to this:
The script has to reset the
Test::Buildercounter on startup.The script needs to prevent
Test::Builderfrom duplicatingSTDOUTandSTDERR, as this seems to be incompatible withPersistentPerl.Scripts with
no_planhave to register aPersistentPerlcleanup handler to display ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access