Unit tests MDL-24909 Unit tests used 5 minute time limit per test class; this is insufficient for gradebook tests on slow server. Changed to use 60 second limit per test function instead. Added constant and comment defining this behaviour.

This commit is contained in:
Sam Marshall 2010-11-01 15:14:37 +00:00
parent 1865b411fd
commit cf617be64e
3 changed files with 15 additions and 5 deletions

View 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);
}

View 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

View 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);