Created
October 30, 2017 19:46
-
-
Save nicomen/8c01cc4e2c72af6c90cc580048c50d04 to your computer and use it in GitHub Desktop.
max 4 parallell jobs while testing syntax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Test::More; | |
use Test::Strict; | |
use Test2::AsyncSubtest; | |
use POSIX ":sys_wait_h"; | |
use Time::HiRes qw/sleep/; | |
my $dir = 'bin'; | |
my @files = Test::Strict::_all_perl_files($dir); | |
run_parallel_tests(4, [ map { my $file = $_; sub { all_perl_files_ok($file); }; } @files ], 'Syntax and strict checks for '. $dir); | |
sub run_parallel_tests { | |
my ($MAX_JOBS, $tests, $name) = @_; | |
my $ast = Test2::AsyncSubtest->new(name => $name); | |
my @tests = @{ $tests || [] }; | |
my %children; | |
while (@tests) { | |
if (keys %children < $MAX_JOBS) { | |
my $pid = $ast->run_fork(shift @tests); | |
$children{$pid}++; | |
} | |
waitpid($_, WNOHANG) && delete $children{$_} for keys %children; | |
last if ! @tests; | |
sleep 0.01; | |
} | |
$ast->finish; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment