From cf617be64ed8260f683fc93364c3b11650c98bbd Mon Sep 17 00:00:00 2001 From: Sam Marshall Date: Mon, 1 Nov 2010 15:14:37 +0000 Subject: [PATCH] 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. --- admin/report/unittest/index.php | 7 ++++++- lib/simpletestlib/readme_moodle.txt | 5 ++++- lib/simpletestlib/test_case.php | 8 +++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/admin/report/unittest/index.php b/admin/report/unittest/index.php index 6ccc938caf6..814ceabe49b 100644 --- a/admin/report/unittest/index.php +++ b/admin/report/unittest/index.php @@ -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); } diff --git a/lib/simpletestlib/readme_moodle.txt b/lib/simpletestlib/readme_moodle.txt index c29913d53c5..67365e45be0 100644 --- a/lib/simpletestlib/readme_moodle.txt +++ b/lib/simpletestlib/readme_moodle.txt @@ -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 diff --git a/lib/simpletestlib/test_case.php b/lib/simpletestlib/test_case.php index be65e81f7f5..bc59e6573a1 100644 --- a/lib/simpletestlib/test_case.php +++ b/lib/simpletestlib/test_case.php @@ -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); -- 2.43.0