Skip to content

Commit

Permalink
Adds improved verbosity output.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal Landau committed Jan 25, 2019
1 parent 9b07f10 commit 96a2bb0
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Runners/PHPUnit/BaseRunner.php
Expand Up @@ -39,7 +39,7 @@ abstract class BaseRunner
* A collection of ExecutableTest objects that have processes
* currently running.
*
* @var array
* @var array|ExecutableTest[]
*/
protected $running = [];

Expand Down
16 changes: 13 additions & 3 deletions src/Runners/PHPUnit/Runner.php
Expand Up @@ -31,9 +31,19 @@ public function run()

while (\count($this->running) || \count($this->pending)) {
foreach ($this->running as $key => $test) {
if (!$this->testIsStillRunning($test)) {
unset($this->running[$key]);
$this->releaseToken($key);
try {
if (!$this->testIsStillRunning($test)) {
unset($this->running[$key]);
$this->releaseToken($key);
}
} catch (\Exception $e) {
if ($this->options->verbose) {
echo "An error for $key: {$e->getMessage()}" . PHP_EOL;
echo "Command: {$test->getLastCommand()}" . PHP_EOL;
echo 'StdErr: ' . $test->getStderr() . PHP_EOL;
echo 'StdOut: ' . $test->getStdout() . PHP_EOL;
}
throw $e;
}
}
$this->fillRunQueue();
Expand Down
22 changes: 13 additions & 9 deletions src/Runners/PHPUnit/Worker/BaseWorker.php
Expand Up @@ -94,18 +94,22 @@ public function isCrashed(): bool
public function checkNotCrashed()
{
if ($this->isCrashed()) {
$lastCommand = isset($this->commands) ? ' Last executed command: ' . end($this->commands) : '';
throw new \RuntimeException(
'This worker has crashed.' . $lastCommand . PHP_EOL
. 'Output:' . PHP_EOL
. '----------------------' . PHP_EOL
. $this->alreadyReadOutput . PHP_EOL
. '----------------------' . PHP_EOL
. $this->readAllStderr()
);
throw new \RuntimeException($this->getCrashReport());
}
}

public function getCrashReport()
{
$lastCommand = isset($this->commands) ? ' Last executed command: ' . end($this->commands) : '';

return 'This worker has crashed.' . $lastCommand . PHP_EOL
. 'Output:' . PHP_EOL
. '----------------------' . PHP_EOL
. $this->alreadyReadOutput . PHP_EOL
. '----------------------' . PHP_EOL
. $this->readAllStderr();
}

public function stop()
{
fclose($this->pipes[0]);
Expand Down
1 change: 1 addition & 0 deletions src/Runners/PHPUnit/Worker/WrapperWorker.php
Expand Up @@ -44,6 +44,7 @@ public function assign(ExecutableTest $test, string $phpunit, array $phpunitOpti
if ($options->verbose) {
echo "\nExecuting test via: $command\n";
}
$test->setLastCommand($command);
$this->execute($command);
}

Expand Down
35 changes: 27 additions & 8 deletions src/Runners/PHPUnit/WrapperRunner.php
Expand Up @@ -70,12 +70,21 @@ private function assignAllPendingTests()
// $phpunitOptions['no-globals-backup'] = null; // removed in phpunit 6.0
while (\count($this->pending)) {
$this->waitForStreamsToChange($this->streams);
foreach ($this->progressedWorkers() as $worker) {
foreach ($this->progressedWorkers() as $key => $worker) {
if ($worker->isFree()) {
$this->flushWorker($worker);
$pending = array_shift($this->pending);
if ($pending) {
$worker->assign($pending, $phpunit, $phpunitOptions, $this->options);
try {
$this->flushWorker($worker);
$pending = array_shift($this->pending);
if ($pending) {
$worker->assign($pending, $phpunit, $phpunitOptions, $this->options);
}
} catch (\Exception $e) {
if ($this->options->verbose) {
$worker->stop();
echo "Error while assigning pending tests for worker $key: {$e->getMessage()}" . PHP_EOL;
echo $worker->getCrashReport();
}
throw $e;
}
}
}
Expand All @@ -96,9 +105,19 @@ private function waitForAllToFinish()
$toCheck = $this->streamsOf($toStop);
$new = $this->waitForStreamsToChange($toCheck);
foreach ($this->progressedWorkers() as $index => $worker) {
if (!$worker->isRunning()) {
$this->flushWorker($worker);
unset($toStop[$index]);
try {
if (!$worker->isRunning()) {
$this->flushWorker($worker);
unset($toStop[$index]);
}
} catch (\Exception $e) {
if ($this->options->verbose) {
$worker->stop();
unset($toStop[$index]);
echo "Error while waiting to finish for worker $index: {$e->getMessage()}" . PHP_EOL;
echo $worker->getCrashReport();
}
throw $e;
}
}
}
Expand Down

0 comments on commit 96a2bb0

Please sign in to comment.