Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
delabiejochen committed Feb 25, 2012
0 parents commit 141e5ff
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.markdown
@@ -0,0 +1,14 @@
PHPUnit Parallel Testing
====================
This repository contains an attempt to do parallel testing with PHPUnit.
The PHP file will loop over the PHPUnit files in the directory you specify and run PHPUnit in separate processes.
You can specify how many tests you want to run at the same time.

When all the tests have run, the php file will echo the output of the tests.

Arguments
---------------------
Run with php parallel.php
Options are:
-d directory/
-m maxParallelTests
77 changes: 77 additions & 0 deletions parallel.php
@@ -0,0 +1,77 @@
<?php

$arguments = getopt("d:m:");

$directory = (isset($arguments['d']) ? $arguments['d'] : "");
$maxParallel = (isset($arguments['m']) ? (int) $arguments['m'] : 5);;

$currentDirectory = dirname(__FILE__);

$results = $files = $runningProcesses = array();


// grab all the *.php files (phpunit tests) in the directory we specified
foreach (glob($directory . "*.php") as $filename) {
$filepath = realpath($currentDirectory) . "/" . $filename;

if ($filepath === __FILE__) {
// don't run this script again :)
continue;
}

$files[] = $filepath;
}

if (empty($files)) {
die("No test files found");
}

$i = 0;

while ($i < sizeof($files)) {
if ($i >= $maxParallel) {
foreach ($runningProcesses as $key => $process) {
$status = proc_get_status($process['handle']);
if ($status['running'] !== true) {
unset($runningProcesses[$key]);
unset($files[$process['nr']]);
$files = array_values($files);
$i--;

// close the process
proc_close($process['handle']);
}
}
continue;
}

$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr
);

$pipes = array();
$process = proc_open('phpunit ' . $files[$i], $descriptorspec, $pipes, null, null);

if (is_resource($process)) {
$runningProcesses[] = array('handle' => $process, 'nr' => $i);

$results[$files[$i]] = stream_get_contents($pipes[1]);

// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
fclose($pipes[1]);
}

$i++;

if (empty($files)) {
break;
}
}

// tests ended - display results
foreach ($results as $testFileName => $result) {
echo "*** Results for [" . $testFileName . "]: \n" . $result . "\n\n";
}

0 comments on commit 141e5ff

Please sign in to comment.