Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.6.5, 2.7.2
-
MOODLE_26_STABLE, MOODLE_27_STABLE
-
MOODLE_26_STABLE, MOODLE_27_STABLE
-
wip-
MDL-47572-master -
Description
This bug is further work on MDL-45654, which didn't properly fix the issue described there. To help searchers, I'll reproduce the sample error output provided in one of the comments below:
There was 1 failure:
1) cronlib_testcase::test_cron_delete_from_temp with data set #0 (array(stdClass, stdClass, stdClass, stdClass, stdClass, stdClass, stdClass, stdClass, stdClass, stdClass, stdClass, stdClass, stdClass), array('/home/marina/repositories/mysql_master/testdata/temp/dir1', '/home/marina/repositories/mysql_master/testdata/temp/dir1/dir1_1', '/home/marina/repositories/mysql_master/testdata/temp/dir1/dir1_1/dir1_1_1', '/home/marina/repositories/mysql_master/testdata/temp/dir1/dir1_1/dir1_1_1/file1_1_1_2', '/home/marina/repositories/mysql_master/testdata/temp/dir1/dir1_2', '/home/marina/repositories/mysql_master/testdata/temp/dir1/dir1_2/file1_1_2_2', '/home/marina/repositories/mysql_master/testdata/temp/dir2', '/home/marina/repositories/mysql_master/testdata/temp/dir4', '/home/marina/repositories/mysql_master/testdata/temp/dir4/dir4_1', '/home/marina/repositories/mysql_master/testdata/temp/dir4/dir4_1/dir4_1_1', '/home/marina/repositories/mysql_master/testdata/temp/file1'))
Failed asserting that two arrays are equal.
— Expected
+++ Actual
@@ @@
5 => '/home/marina/repositories/mys..._1_2_2'
- 6 => '/home/marina/repositories/mysql_master/testdata/temp/dir2'
- 7 => '/home/marina/repositories/mysql_master/testdata/temp/dir4'
- 8 => '/home/marina/repositories/mysql_master/testdata/temp/dir4/dir4_1'
- 9 => '/home/marina/repositories/mysql_master/testdata/temp/dir4/dir4_1/dir4_1_1'
- 10 => '/home/marina/repositories/mys.../file1'
+ 6 => '/home/marina/repositories/mysql_master/testdata/temp/dir4'
+ 7 => '/home/marina/repositories/mysql_master/testdata/temp/dir4/dir4_1'
+ 8 => '/home/marina/repositories/mysql_master/testdata/temp/dir4/dir4_1/dir4_1_1'
+ 9 => '/home/marina/repositories/mysql_master/testdata/temp/file1'
)/home/marina/repositories/mysql_master/moodle/lib/tests/cronlib_test.php:179
/home/marina/repositories/mysql_master/moodle/lib/phpunit/classes/basic_testcase.php:64To re-run:
vendor/bin/phpunit cronlib_testcase lib/tests/cronlib_test.php
As described in my comment toward the end of that issue (when I was seeking to reopen it):
I've been able to reliably reproduce the PHP unit testing failure with Totara 2.6.10 (based on Moodle 2.6.5), and have a patch that does fix the issue.
There are two problems.
First, the same timestamp is not used throughout testing, so that failures can happen because a test takes too long to run. The patch I will seek to add fixes this by storing the result of time() once and passing it in a new optional parameter to cron_delete_from_temp so that its tests can use that fixed timestamp and not be subject to variations in the time taken to run tests.
Secondly, in the week after daylight saving starts or ends (this week in Oz, which is why I found it!), the number of seconds to the same time last week is not 7 * 24 * 60 * 60. The $lastweekstime variable therefore needs to calculate the difference between strtotime('-1 week') and time(), and use that value.
With both of these changes, I've reliably and successfully run the unit test.