com phpruntests: phpruntests - update taskScheduler - fixed out-of-memory-bug while running large tests: src/taskScheduler/rtTaskSchedulerFile.php
src/taskScheduler/rtTaskTestGroup.php src/testcase/output/rtTestOutputWriterXML.php src/testgroup/rtPhpTestGroup.php
| From: | David Soria Parra | Date: | Mon, 29 Jun 2009 22:00:13 +0000 |
| Subject: | com phpruntests: phpruntests - update taskScheduler - fixed out-of-memory-bug while running large tests: src/taskScheduler/rtTaskSchedulerFile.php src/taskScheduler/rtTaskTestGroup.php src/testcase/output/rtTestOutputWriterXML.php src/testgroup/rtPhpTestGroup.php |
||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-66389@lists.php.net to get a copy of this message | ||
Commit: 98ff348d46d01630d4df40d79f25d29e4b73f6a1
Author: Georg Gradwohl <g2@php.net> Mon, 29 Jun 2009 22:00:13 +0000
Parents: 0bfa9acbff6e23d27ca753ee2ba554e93db17210
Branches: master
Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=98ff348d46d01630d4df40d79f25d29e4b73f6a1
Log:
phpruntests - update taskScheduler - fixed out-of-memory-bug while running large tests
Changed paths:
M src/taskScheduler/rtTaskSchedulerFile.php
M src/taskScheduler/rtTaskTestGroup.php
M src/testcase/output/rtTestOutputWriterXML.php
M src/testgroup/rtPhpTestGroup.php
Diff:
diff --git a/src/taskScheduler/rtTaskSchedulerFile.php b/src/taskScheduler/rtTaskSchedulerFile.php
index 1a1a517..285fe4b 100644
--- a/src/taskScheduler/rtTaskSchedulerFile.php
+++ b/src/taskScheduler/rtTaskSchedulerFile.php
@@ -17,11 +17,9 @@ class rtTaskSchedulerFile extends rtTaskScheduler
{
const TMP_FILE = 'taskFile';
- private $inputQueue = NULL; // the input-queue (only used by the sender)
private $pidStore = array(); // stores the pids of all child-processes
private $groupTasks = false; // are the tasks stored in groups?
-
- private $tmpTaskList = array();
+
/**
* the constructor
@@ -59,8 +57,6 @@ class rtTaskSchedulerFile extends rtTaskScheduler
$this->taskList = $taskList;
}
-
-
/**
* sets the number of child-processes.
* in the case of using a multidimensional task-list this parameter is
@@ -76,7 +72,6 @@ class rtTaskSchedulerFile extends rtTaskScheduler
}
}
-
/**
* starts the sender, the receiver and forks the defined
@@ -98,8 +93,8 @@ class rtTaskSchedulerFile extends rtTaskScheduler
$this->processCount = sizeof($this->taskList);
}
+ // distribute the task to the children
$this->createTaskFiles();
-
// fork the child-processes
for ($i=0; $i<$this->processCount; $i++) {
@@ -126,7 +121,7 @@ class rtTaskSchedulerFile extends rtTaskScheduler
pcntl_waitpid($this->pidStore[$i], $status);
}
- // ensure that the tmp-files are completly written
+ // ensure that the tmp-files are completely written
sleep(1);
// collecting the results
@@ -137,8 +132,7 @@ class rtTaskSchedulerFile extends rtTaskScheduler
return;
}
-
-
+
/**
* creates a temporary file for each child which stores the allocated
@@ -180,8 +174,9 @@ class rtTaskSchedulerFile extends rtTaskScheduler
}
-
/**
+ *
+ *
* @return void
*/
private function receiver()
@@ -202,7 +197,7 @@ class rtTaskSchedulerFile extends rtTaskScheduler
}
$index = $task->getIndex();
- $task->finish($cid);
+ $task->evaluate($cid);
if ($this->groupTasks == true) {
@@ -219,10 +214,12 @@ class rtTaskSchedulerFile extends rtTaskScheduler
return;
}
-
/**
+ * executes the assigned tasks and stores the serialized task-object in
+ * the task-file.
+ *
* @param int $cid the child-id
* @return void
*/
@@ -231,24 +228,26 @@ class rtTaskSchedulerFile extends rtTaskScheduler
$indexList = file_get_contents(self::TMP_FILE.$cid);
$indexList = explode(';', $indexList);
array_pop($indexList);
-
- $response = '';
+
+ file_put_contents(self::TMP_FILE.$cid, '');
foreach ($indexList as $index) {
if ($this->groupTasks == true) {
- $task = $this->taskList[$cid][$index];
+ $task = $this->taskList[$cid][$index];
} else {
$task = $this->taskList[$index];
}
$task->run();
$task->setIndex($index);
-
- $response .= serialize($task)."[END-TEST-OBJECT]";
+
+ print "$cid - ".$task->getDir()." - ".round(memory_get_usage()/1024,
2)."\n";
+ flush();
+
+ $response = serialize($task)."[END-TEST-OBJECT]";
+ file_put_contents(self::TMP_FILE.$cid, $response, FILE_APPEND);
}
-
- file_put_contents(self::TMP_FILE.$cid, $response);
exit(0);
}
diff --git a/src/taskScheduler/rtTaskTestGroup.php b/src/taskScheduler/rtTaskTestGroup.php
index c0a9d04..373c89d 100644
--- a/src/taskScheduler/rtTaskTestGroup.php
+++ b/src/taskScheduler/rtTaskTestGroup.php
@@ -15,35 +15,58 @@ class rtTaskTestGroup extends rtTask implements rtTaskInterface
{
private $runConfiguration;
private $subDirectory;
- private $testGroup;
+ private $results;
+
public function __construct($runConfiguration, $subDirectory)
{
$this->runConfiguration = $runConfiguration;
$this->subDirectory = $subDirectory;
}
-
+
+
+ /**
+ * called by the child-process
+ * executes the the test-group
+ */
public function run()
{
- $this->testGroup = new rtPhpTestGroup($this->runConfiguration, $this->subDirectory);
- $this->testGroup->runGroup($this->runConfiguration);
-
+ $testGroup = new rtPhpTestGroup($this->runConfiguration, $this->subDirectory);
+ $testGroup->runGroup($this->runConfiguration);
+ $this->results = $testGroup->getResults();
return true;
}
- public function finish($cid=null) {
-
- if (!is_null($cid)) {
- print "\n$cid - "..$this->subDirectory."\n";
- }
-
+
+ /**
+ * called by the receiver (parent-process)
+ * writes the results to the OutputWriter
+ *
+ * @param $cid the child-id
+ */
+ public function evaluate($cid=null)
+ {
$outType = 'list';
if ($this->runConfiguration->hasCommandLineOption('o')) {
$outType = $this->runConfiguration->getCommandLineOption('o');
}
-
- $this->testGroup->writeGroup($outType, $cid);
+
+ $testOutputWriter = rtTestOutputWriter::getInstance($this->results, $outType);
+ $testOutputWriter->write($this->subDirectory, $cid);
}
+
+
+ public function getDir()
+ {
+ return $this->subDirectory;
+ }
+
+
+ public function getResults()
+ {
+ return $this->results;
+ }
+
}
diff --git a/src/testcase/output/rtTestOutputWriterXML.php
b/src/testcase/output/rtTestOutputWriterXML.php
index e94d23b..f3e0ec4 100644
--- a/src/testcase/output/rtTestOutputWriterXML.php
+++ b/src/testcase/output/rtTestOutputWriterXML.php
@@ -52,10 +52,8 @@ class rtTestOutputWriterXML extends rtTestOutputWriter
/**
- *
- *
+ *
* @param array of rtTestResults
- *
*/
public function init (array $testResults)
{
@@ -103,5 +101,6 @@ class rtTestOutputWriterXML extends rtTestOutputWriter
return null;
}
+
}
-?>
+?>
\ No newline at end of file
diff --git a/src/testgroup/rtPhpTestGroup.php b/src/testgroup/rtPhpTestGroup.php
index 54b2c26..1fd09ad 100644
--- a/src/testgroup/rtPhpTestGroup.php
+++ b/src/testgroup/rtPhpTestGroup.php
@@ -75,5 +75,12 @@ class rtPhpTestGroup
$testOutputWriter = rtTestOutputWriter::getInstance($this->results, $outType);
$testOutputWriter->write($this->testDirectory, $cid);
}
+
+
+ public function getResults()
+ {
+ return $this->results;
+ }
+
}
?>