Skip to content

Commit e035fe1

Browse files
committed
If a test does not have any data after 60 seconds of waiting, assume that
it died a horrible death and kill it. This is useful on windows when a message box is popped-up during an automated test-run.
1 parent 27e3d64 commit e035fe1

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

run-tests.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,40 @@ function error_report($testname,$logname,$tested)
516516
}
517517
}
518518

519+
function system_with_timeout($commandline)
520+
{
521+
$data = "";
522+
523+
$proc = proc_open($commandline, array(1 => array('pipe', 'w')), $pipes);
524+
525+
if (!$proc)
526+
return false;
527+
528+
while (true) {
529+
/* hide errors from interrupted syscalls */
530+
$r = $pipes;
531+
$w = null;
532+
$e = null;
533+
$n = stream_select($r, $w, $e, 60);
534+
535+
if ($n == 0) {
536+
/* timed out */
537+
$data .= "\n ** ERROR: process timed out **\n";
538+
proc_terminate($proc);
539+
return $data;
540+
} else if ($n) {
541+
$line = fgets($pipes[1]);
542+
if ($line === false) {
543+
/* EOF */
544+
break;
545+
}
546+
$data .= $line;
547+
}
548+
}
549+
$code = proc_close($proc);
550+
return $data;
551+
}
552+
519553
//
520554
// Run an individual test case.
521555
//
@@ -667,7 +701,8 @@ function run_test($php,$file)
667701
COMMAND $cmd
668702
";
669703

670-
$out = `$cmd`;
704+
// $out = `$cmd`;
705+
$out = system_with_timeout($cmd);
671706

672707
@unlink($tmp_post);
673708

0 commit comments

Comments
 (0)