com phpruntests: phpruntests - moved rtException in root, replaced PhpRunnerException - added singal-handler to taskSchedulerFile: src/rtClassMap.php
src/rtException.php src/taskScheduler/rtTaskSchedulerFile.php src/testcase/rtPhpRunner.php src/testcase/sections/executablesections/rtCleanSection.php
src/testcase/sections/executablesections/rtFileSection.php src/testcase/sections/executablesections/rtSkipIfSection.php
| From: | David Soria Parra | Date: | Wed, 08 Jul 2009 19:23:23 +0000 |
| Subject: | com phpruntests: phpruntests - moved rtException in root, replaced PhpRunnerException - added singal-handler to taskSchedulerFile: src/rtClassMap.php src/rtException.php src/taskScheduler/rtTaskSchedulerFile.php src/testcase/rtPhpRunner.php src/testcase/sections/executablesections/rtCleanSection.php src/testcase/sections/executablesections/rtFileSection.php src/testcase/sections/executablesections/rtSkipIfSection.php |
||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-66350@lists.php.net to get a copy of this message | ||
Commit: 1e254777eab096431a6b69102897618ae93004d6
Author: Georg Gradwohl <g2@php.net> Wed, 8 Jul 2009 19:23:23 +0000
Parents: 479657e69231e6cc42651dd2c1d2b282ccbe47fa
Branches: master
Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=1e254777eab096431a6b69102897618ae93004d6
Log:
phpruntests - moved rtException in root, replaced PhpRunnerException - added singal-handler to
taskSchedulerFile
Changed paths:
M src/rtClassMap.php
A src/rtException.php
M src/taskScheduler/rtTaskSchedulerFile.php
M src/testcase/rtPhpRunner.php
M src/testcase/sections/executablesections/rtCleanSection.php
M src/testcase/sections/executablesections/rtFileSection.php
M src/testcase/sections/executablesections/rtSkipIfSection.php
Diff:
diff --git a/src/rtClassMap.php b/src/rtClassMap.php
index da47c67..fea7656 100644
--- a/src/rtClassMap.php
+++ b/src/rtClassMap.php
@@ -8,7 +8,6 @@
*/
$rtClassMap = array(
'rtEnvironmentException' =>
'configuration/exceptions/rtEnvironmentException.php',
- 'rtException' =>
'configuration/exceptions/rtException.php',
'rtMissingArgumentException' =>
'configuration/exceptions/rtMissingArgumentException.php',
'rtUnknownIniSettingException' =>
'configuration/exceptions/rtUnknownIniSettingException.php',
'rtUnknownOptionException' =>
'configuration/exceptions/rtUnknownOptionException.php',
@@ -46,6 +45,7 @@ $rtClassMap = array(
'rtAutoload' => 'rtAutoload.php',
'rtClassMap' => 'rtClassMap.php',
'rtDirectoryList' => 'rtDirectoryList.php',
+ 'rtException' => 'rtException.php',
'rtPhptFilterIterator' =>
'rtPhptFilterIterator.php',
'rtText' => 'rtText.php',
'rtUtil' => 'rtUtil.php',
@@ -55,7 +55,6 @@ $rtClassMap = array(
'rtTaskSchedulerFile' =>
'taskScheduler/rtTaskSchedulerFile.php',
'rtTaskSchedulerMsgQ' =>
'taskScheduler/rtTaskSchedulerMsgQ.php',
'rtTaskTestGroup' =>
'taskScheduler/rtTaskTestGroup.php',
- 'rtCodeRunnerException' =>
'testcase/exceptions/rtCodeRunnerException..php',
'rtPhpRunnerException' =>
'testcase/exceptions/rtPhpRunnerException.php',
'rtTestOutputWriterCSV' =>
'testcase/output/rtTestOutputWriterCSV.php',
'rtTestOutputWriterList' =>
'testcase/output/rtTestOutputWriterList.php',
diff --git a/src/rtException.php b/src/rtException.php
new file mode 100755
index 0000000..cb78b51
--- /dev/null
+++ b/src/rtException.php
@@ -0,0 +1,18 @@
+<?php
+
+class rtException extends RuntimeException
+{
+ public function __toString()
+ {
+ $r =
"\n--------------------------------------------------------------------------------\n";
+ $r .= "RUN-TESTS EXCEPTION\n";
+ $r .= $this->getMessage()." (CODE ".$this->getCode().")\n";
+ $r .= $this->getFile().":".$this->getLine()."\n\n";
+ $r .= $this->getTraceAsString();
+ $r .=
"\n--------------------------------------------------------------------------------\n";
+
+ return $r;
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/src/taskScheduler/rtTaskSchedulerFile.php b/src/taskScheduler/rtTaskSchedulerFile.php
index 15ca5ad..63636da 100644
--- a/src/taskScheduler/rtTaskSchedulerFile.php
+++ b/src/taskScheduler/rtTaskSchedulerFile.php
@@ -21,6 +21,18 @@ class rtTaskSchedulerFile extends rtTaskScheduler
private $groupTasks = false; // are the tasks stored in groups?
+ /**
+ * the signal-handler is called by the interrupt- or quit-signal. this is
+ * necessary to cleanup the tmp files and terminate the script correct.
+ *
+ * @param int $signal
+ */
+ public static function signalHandler($signal)
+ {
+ exit(0);
+ }
+
+
/**
* sets the task-list which has to be an array of task-objects.
* it's also possible to use a multidimensional array. in this case the
@@ -76,6 +88,8 @@ class rtTaskSchedulerFile extends rtTaskScheduler
if ($this->processCount > sizeof($this->taskList)) {
$this->processCount = sizeof($this->taskList);
}
+
+
// distribute the task to the children
$this->distributeTasks();
@@ -99,7 +113,13 @@ class rtTaskSchedulerFile extends rtTaskScheduler
break;
}
}
+
+
+ // register signal-handler
+ pcntl_signal(SIGINT, "rtTaskSchedulerFile::signalHandler");
+ pcntl_signal(SIGQUIT, "rtTaskSchedulerFile::signalHandler");
+
// wait until all child-processes are terminated
for ($i=0; $i<$this->processCount; $i++) {
pcntl_waitpid($this->pidStore[$i], $status);
@@ -174,6 +194,8 @@ class rtTaskSchedulerFile extends rtTaskScheduler
unlink(self::TMP_FILE.$cid);
}
+
+ $this->pidStore = array();
}
diff --git a/src/testcase/rtPhpRunner.php b/src/testcase/rtPhpRunner.php
index e7aacb8..cdd5014 100644
--- a/src/testcase/rtPhpRunner.php
+++ b/src/testcase/rtPhpRunner.php
@@ -58,6 +58,8 @@ class rtPhpRunner
fclose($pipes[0]);
+ $counter = 0;
+
while (true) {
/* hide errors from interrupted syscalls */
$r = $pipes;
@@ -67,14 +69,19 @@ class rtPhpRunner
$n = @stream_select($r, $w, $e, $this->timeOut);
if ($n === false) {
- throw new rtPhpRunnerException('Stream select failure in rtPhpRunner');
+ throw new rtException('Stream select failure in rtPhpRunner');
} else if ($n === 0) {
proc_terminate($proc);
- throw new rtPhpRunnerException ('The process running test code has timed out
in rtPhpRunner');
+ throw new rtException('The process running test code has timed out in
rtPhpRunner');
} else if ($n > 0) {
- $line = fread($pipes[1], 8192);
+ $counter++;
+ if ($counter > 10) {
+ proc_terminate($proc);
+ throw new rtException('The process running test code has timed out in
rtPhpRunner');
+ }
+ $line = fread($pipes[1], 8192);
if (strlen($line) == 0) {
- /* EOF */
+ // EOF
break;
}
$data .= (binary) $line;
diff --git a/src/testcase/sections/executablesections/rtCleanSection.php
b/src/testcase/sections/executablesections/rtCleanSection.php
index ace4959..89d1e38 100644
--- a/src/testcase/sections/executablesections/rtCleanSection.php
+++ b/src/testcase/sections/executablesections/rtCleanSection.php
@@ -43,7 +43,7 @@ class rtCleanSection extends rtExecutableSection
$testStatus->setMessage('fail_clean','Execution of clean section
failed: '.trim($this->output) );
}
- } catch (rtPhpRunnerException $e) {
+ } catch (rtException $e) {
$testStatus->setTrue('fail_clean');
$testStatus->setMessage('fail_clean',$e->getMessage);
}
diff --git a/src/testcase/sections/executablesections/rtFileSection.php
b/src/testcase/sections/executablesections/rtFileSection.php
index dc3f7b5..5222dc5 100644
--- a/src/testcase/sections/executablesections/rtFileSection.php
+++ b/src/testcase/sections/executablesections/rtFileSection.php
@@ -67,7 +67,7 @@ class rtFileSection extends rtExecutableSection
}
- } catch (rtPhpRunnerException $e) {
+ } catch (rtException $e) {
$testStatus->setTrue('fail');
$testStatus->setMessage('fail', $e->getMessage() );
}
diff --git a/src/testcase/sections/executablesections/rtSkipIfSection.php
b/src/testcase/sections/executablesections/rtSkipIfSection.php
index 44276e1..6302ae1 100644
--- a/src/testcase/sections/executablesections/rtSkipIfSection.php
+++ b/src/testcase/sections/executablesections/rtSkipIfSection.php
@@ -51,7 +51,7 @@ class rtSkipIfSection extends rtExecutableSection
$testStatus->setMessage('warn', $matches[1]);
}
}
- } catch (rtPhpRunnerException $e) {
+ } catch (rtException $e) {
$testStatus->setTrue('fail_skip');
$testStatus->setMessage('fail_skip', 'Failed to execute skipif
section' . $e->getMessage());
}