MDL-47572 unit tests: make cronlib_testcase DST immune
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 30 Mar 2015 23:21:18 +0000 (01:21 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 30 Mar 2015 23:21:18 +0000 (01:21 +0200)
Disclaimer: I've assigned this commit to MDL-47572 because it's
the issue where I've seen related changes.

Since a couple of days ago, both CI servers were failing. A couple
of days ago it was DST change in Europe/Madrid (that is the PHP
default TZ used by them).

Tests pass perfectly if the TZ is set to any other place not affected
by DST (Australia/Perth, for example).

Really the issue is a wrong mix of functions supporting DST and
functions not supporting them.

But, with current implementation (checking +-60 seconds around a time)
and with a DST change in the middle... this unit tests was going to be
failing for an entire week. And that's not acceptable for CIs.

So, I've changed the intervals, to be bigger than 1h (exactly 1h1s), so
they will be immune to the DST change/partial support.

Ideally all operations should be working in the same way (with or
without DST considered), but that's out from the scope of getting this
test stable enough and passing.

lib/tests/cronlib_test.php

index 4d7a1b5..66b33a9 100644 (file)
@@ -44,8 +44,8 @@ class cronlib_testcase extends basic_testcase {
 
         // Relative time stamps. Did you know data providers get executed during phpunit init?
         $lastweekstime = strtotime('-1 week') - time();
-        $beforelastweekstime = $lastweekstime - 60;
-        $afterlastweekstime = $lastweekstime + 60;
+        $beforelastweekstime = $lastweekstime - 3600 - 1; // At least 1h and 1s diff (make it DST immune).
+        $afterlastweekstime = $lastweekstime + 3600 + 1; // At least 1h and 1s diff (make it DST immune).
 
         $nodes = array();
         // Really old directory to remove.