Skip to content

Commit d04639b

Browse files
[PhpUnitBridge] Kill the last concurrent process when it stales for more than 60s
1 parent ffd2885 commit d04639b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Diff for: bin/simple-phpunit.php

+23
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla
398398
}
399399
}
400400

401+
$lastOutput = null;
402+
$lastOutputTime = null;
403+
401404
while ($runningProcs) {
402405
usleep(300000);
403406
$terminatedProcs = [];
@@ -410,6 +413,26 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla
410413
}
411414
}
412415

416+
if (!$terminatedProcs && 1 === count($runningProcs)) {
417+
$component = key($runningProcs);
418+
419+
$output = file_get_contents("$component/phpunit.stdout");
420+
$output .= file_get_contents("$component/phpunit.stderr");
421+
422+
if ($lastOutput !== $output) {
423+
$lastOutput = $output;
424+
$lastOutputTime = microtime(true);
425+
} elseif (microtime(true) - $lastOutputTime > 60) {
426+
echo "\033[41mTimeout\033[0m $component\n\n";
427+
428+
if ('\\' === \DIRECTORY_SEPARATOR) {
429+
exec(sprintf('taskkill /F /T /PID %d 2>&1', $procStatus['pid']), $output, $exitCode);
430+
} else {
431+
proc_terminate(current($runningProcs));
432+
}
433+
}
434+
}
435+
413436
foreach ($terminatedProcs as $component => $procStatus) {
414437
foreach (['out', 'err'] as $file) {
415438
$file = "$component/phpunit.std$file";

0 commit comments

Comments
 (0)