version 0.20
Test::Parallel is a simple object interface used to launch test in parallel. It uses Parallel::ForkManager to launch tests in parallel and get the results.
Alias for basic methods are available
ok is isnt like unlike cmp_ok is_deeply
It can be used nearly the same way as Test::More
use Test::More tests => 8; use Test::Parallel; my $p = Test::Parallel->new(); # queue some tests that can be parallelized $p->ok( sub { 1 }, "can do ok" ); $p->is( sub { 42 }, 42, "can do is" ); $p->isnt( sub { 42 }, 51, "can do isnt" ); $p->like( sub { "abc" }, qr{ab}, "can do like: match ab"); $p->unlike( sub { "abc" }, qr{xy}, "can do unlike: match ab"); $p->cmp_ok( sub { 'abc' }, 'eq', 'abc', "can do cmp ok"); $p->cmp_ok( sub { '1421' }, '==', 1_421, "can do cmp ok"); $p->is_deeply( sub { [ 1..15 ] }, [ 1..15 ], "can do is_deeply"); # run the tests in background $p->done();
You could also use the results returned by the test function to launch multiple test
use Test::Parallel; use Test::More; my $p = Test::Parallel->new(); $p->add( sub { # will be launched in parallel # any code that take time to execute need to go there my $time = int( rand(42) ); sleep( $time ); return { number => 123, time => $time }; }, sub { # will be execute from the main thread ( not in parallel ) my $result = shift; is $result->{number} => 123; cmp_ok $result->{time}, '<=', 42; } ); $p->done();
Create a new Test::Parallel object. By default it will use the number of cores you have as a maximum limit of parallelized job, but you can control this value with two options : - max_process : set the maximum process to this value - max_process_per_cpu : set the maximum process per cpu, this value will be multiplied by the number of cpu ( core ) avaiable on your server - max_memory : in MB per job. Will use the minimum between #cpu and total memory available / max_memory
my $p = Test::Parallel->new() or Test::Parallel->new( max_process => N ) or Test::Parallel->new( max_process_per_cpu => P ) or Test::Parallel->new( max_memory => M )
Same as Test::More::ok but need a code ref in first argument
Same as Test::More::is but need a code ref in first argument
Same as Test::More::isnt but need a code ref in first argument
Same as Test::More::like but need a code ref in first argument
Same as Test::More::unlike but need a code ref in first argument
Same as Test::More::cmp_ok but need a code ref in first argument
Same as Test::More::is_deeply but need a code ref in first argument
You can manually add some code to be launched in parallel, but if you uses this method you will need to manipulate yourself the final result.
Prefer using one of the following methods :
will run and wait for all jobs added you do not need to use this method except if you prefer to add jobs yourself and manipulate the results
you need to call this function when you are ready to launch all jobs in bg this method will call run and also check results with Test::More
get an array of results, in the same order of jobs
alias to results
To install Test::Parallel, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Parallel
CPAN shell
perl -MCPAN -e shell install Test::Parallel
For more information on module installation, please visit the detailed CPAN module installation guide.