Introduction
Lightspeed is a PHP package for speeding up test suite execution.
It operates on a simple idea:
By running your tests on more machines at once, you can reduce the time it takes to run the suite.
And by achieving faster test execution, you get a few pretty good things:
- Code can be deployed sooner,
- Developers (you!) can get feedback faster,
- and so on...
How does it work?
Is this magic?
Lightspeed splits up your tests in a deterministic way depending on how many nodes are in use. The tests are evenly distributed across all nodes and are run in parallel.
The diagram below shows how tests are split between nodes.
So the more nodes you can put towards running your tests, the faster they can finish running.
Lightspeed works with tests written in both PHPUnit and Pest.
INFO
If your test suite comprises only unit tests and runs in less than a minute or two, you probably won't see any benefit in Lightspeed. Lightspeed shines where tests involve intensive operations or integration tests or for large test suites with thousands of tests.
Is it really faster?
You may be thinking:
Tests aren't all created equal. Some run longer than others.
And you'd be correct.
Your tests are likely to have a mixture of unit tests and integration tests. Or perhaps you have Feature tests (shout out to Laravel 🤘) that test using a database. The execution time of these tests might vary from microseconds all the way up to a few seconds or more.
If tests are randomly divided up, it wont be optimal. What if the first node gets all the slow tests and a second node gets all the fast tests? Correct. It will still be faster than running synchronous, but there is more speed we can achieve.
This is where Lightspeed Pro comes in. It tracks historic test execution time and factors that into the test distribution so that test suites execute in the minimal amount of time possible.
We are actively working on this paid extension to Lightspeed and looking for early adopters. Please email us if you are interested or want to know more.
TIP
If you still have questions, you can check out the FAQ for some common questions or send us an email at jarryd@tilbrooktech.com.