2017 © Pedro Peláez
 

library peridot-concurrency

Concurrent spec runner for the peridot bdd framework

image

peridot-php/peridot-concurrency

Concurrent spec runner for the peridot bdd framework

  • Tuesday, February 24, 2015
  • by brianium
  • Repository
  • 4 Watchers
  • 11 Stars
  • 17,438 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 3 Versions
  • 9 % Grown

The README.md

peridot-concurrency

Lets run our specs a lot faster!, (*1)

Build Status HHVM Status Scrutinizer Code Quality Coverage Status, (*2)

This plugin includes a runner and reporter that allows you to run your Peridot tests concurrently! Have a bunch of slow WebDriver tests? How about a bunch of DB tests? Tired of waiting? Why not run them at the same time!?!?, (*3)

How does it work?

peridot-concurrency leverages good old fashioned non-blocking IO to run our tests concurrently. This plugin creates N worker processes as specified on the command line, and each worker communicates with the main process as test results become available. The function responsible for polling workers is the stream_select function., (*4)

Usage

You can install via composer:, (*5)

composer require --dev peridot-php/peridot-concurrency

peridot-concurreny can be added to your test workflow like any Peridot extension - that is via the peridot.php file:, (*6)

use Evenement\EventEmitterInterface;
use Peridot\Concurrency\ConcurrencyPlugin;

return function (EventEmitterInterface $emitter) {
    $concurrency = new ConcurrencyPlugin($emitter);
};

After registering the plugin, your usage screen should have a couple of new options:, (*7)

Peridot concurrency usage, (*8)

--concurrent

This is how you signal Peridot to run your tests concurrently. This will start as many worker processes as specified by the new -p option (defaulting to 5). In addition to starting workers, this will override the Peridot reporter to use the ConcurrentReporter provided by this plugin. This reporter prevents output from being garbled, and offers useful information like the time it takes each suite file to run., (*9)

--processes (-p)

This new option can be used to specify the number of worker processes to start. It defaults to 5, and the sweet spot will vary from machine to machine., (*10)

OS Support

Due to limitations of the Windows operating system, it is currently not supported by the peridot-concurreny plugin. This has to do with the stream_select function not being able to work with file descriptors returned from proc_open on the Windows operating system., (*11)

stream_select is currently the most efficient "out-of-the-box" solution for this type of work, but stay tuned for a "process per test" runner that works on Windows, and a pthreads based runner where the extension is available., (*12)

Performance

There is some overhead with creating processes, so not every suite will improve from using concurrency. For example, if you have a suite that runs in 68ms, it's hard to improve on that. BUT! The test suites run so far, have noticed significant speed improvements, even on the unit level., (*13)

peridot-concurrency runs it's own tests concurrently:, (*14)

before

Peridot concurrency suite run serially, (*15)

after

Peridot concurrency suite run concurrently, (*16)

On the machines tested, Peridot's own test suite was run in 1/4th of the time! You can see peridot-concurrency's travis build to see even faster run times., (*17)

The thing to note here is that these are just unit test suites. The amount of time saved running a bulky integration or functional test suite would be even more significant (examples coming soon)., (*18)

Fine tuning

As mentioned before, the exact number of processes to use will vary from machine to machine. Try experimenting with different process numbers to get the most speed out of peridot-concurrency., (*19)

Test Tokens

Each worker process has its own unique ID, and it is surfaced as an environment variable PERIDOT_TEST_TOKEN. This may be useful for creating unique resources based on this token. For instance:, (*20)

$id = getenv('PERIDOT_TEST_TOKEN');
$dbname = "mydb_$id";
//create and seed DB identified by $dbname
//do database things

Contributing

Concurrency can be tricky business. If you have any issues or ideas please let us know! Pull requests are always welcome., (*21)

The Versions