Unit tests MDL-24909 Unit tests used 5 minute time limit per test class; this is...
authorSam Marshall <s.marshall@open.ac.uk>
Mon, 1 Nov 2010 15:14:37 +0000 (15:14 +0000)
committerSam Marshall <s.marshall@open.ac.uk>
Mon, 1 Nov 2010 15:14:37 +0000 (15:14 +0000)
admin/report/unittest/index.php
lib/simpletestlib/readme_moodle.txt
lib/simpletestlib/test_case.php

index 6ccc938..814ceab 100644 (file)
@@ -33,6 +33,12 @@ $unittest = true;
 global $UNITTEST;
 $UNITTEST = new stdClass();
 
+// This limit is the time allowed per individual test function. Please do not
+// increase this value. If you get a PHP time limit when running unit tests,
+// find the unit test which is running slowly, and either make it faster,
+// split it into multiple tests, or call set_time_limit within that test.
+define('TIME_ALLOWED_PER_UNIT_TEST', 60);
+
 // Print the header.
 $strtitle = get_string('unittests', 'simpletest');
 
@@ -90,7 +96,6 @@ if (!is_null($path)) {
             $title = get_string('moodleunittests', 'simpletest', $displaypath);
         }
         echo $OUTPUT->heading($title);
-        set_time_limit(300); // 5 mins
         $test->run($reporter);
     }
 
index c29913d..67365e4 100644 (file)
@@ -12,5 +12,8 @@ Changes:
  * modified run() in test_case.php - skipping tests that need fake db if prefix not set
  * search replace deprecated "=& new"
  * MDL-20876 - replaced deprecated split() with explode()
+ * test_case.php - added TIME_ALLOWED_PER_UNIT_TEST constant which
+   resets php time limit for each test function - MDL-24909. Marked with
+   comments (replace existing per-class hack in test_case.php).
 
-skodak, Tim
+skodak, Tim, sammarshall
index be65e81..bc59e65 100644 (file)
@@ -138,6 +138,11 @@ class SimpleTestCase {
                     $reporter->paintCaseStart($this->getLabel());
                     $started = true;
                 }
+//moodlefix begins
+                if (defined('TIME_ALLOWED_PER_UNIT_TEST')) {
+                    set_time_limit(TIME_ALLOWED_PER_UNIT_TEST);
+                }
+//moodlefix ends
                 $invoker = &$this->_reporter->createInvoker($this->createInvoker());
                 $invoker->before($method);
                 $invoker->invoke($method);
@@ -607,9 +612,6 @@ class TestSuite {
                     $reporter->paintSkip("Unit test \"{$class}\" of type UnitTestCaseUsingDatabase skipped. Must define different, non-conflicting \$CFG->unittestprefix to be runnable.");
                     continue;
                 }
-                if ($currenttl = @ini_get('max_execution_time')) {
-                    @ini_set('max_execution_time', $currenttl);
-                }
                 // moodle hack end
                 $test = new $class();
                 $test->run($reporter);