Permalink
Browse files

Merge branch 'MDL-35109-available-updates_23' of git://github.com/mud…

…rd8mz/moodle into MOODLE_23_STABLE
  • Loading branch information...
2 parents 3d1cbc0 + 903d13c commit 8169e2f46bec5297cdce7b57323f9671a0ca4ff9 Sam Hemelryk committed Sep 3, 2012
Showing with 39 additions and 10 deletions.
  1. +1 −1 lib/pluginlib.php
  2. +38 −9 lib/tests/pluginlib_test.php
View
@@ -1064,7 +1064,7 @@ protected function cron_has_fresh_fetch($now) {
return true;
}
- if ($now - $recent > HOURSECS) {
+ if ($now - $recent > 24 * HOURSECS) {
return false;
}
@@ -103,7 +103,7 @@ public function test_cron_initial_fetch() {
*/
public function test_cron_has_fresh_fetch() {
$provider = testable_available_update_checker::instance();
- $provider->fakerecentfetch = time() - 59 * MINSECS; // fetched an hour ago
+ $provider->fakerecentfetch = time() - 23 * HOURSECS; // fetched 23 hours ago
$provider->fakecurrenttimestamp = -1;
$provider->cron();
$this->assertTrue(true); // we should get here with no exception thrown
@@ -127,23 +127,52 @@ public function test_cron_has_outdated_fetch() {
*/
public function test_cron_offset_execution_not_yet() {
$provider = testable_available_update_checker::instance();
- $provider->fakerecentfetch = time() - 24 * HOURSECS;
- $provider->fakecurrenttimestamp = mktime(1, 40, 02); // 01:40:02 AM
+ $provider->fakecurrenttimestamp = mktime(1, 40, 02); // 01:40:02 AM today
+ $provider->fakerecentfetch = $provider->fakecurrenttimestamp - 24 * HOURSECS;
$provider->cron();
$this->assertTrue(true); // we should get here with no exception thrown
}
/**
- * The first cron after 01:42 AM today should fetch the data
+ * The first cron after 01:42 AM today should fetch the data and then
+ * it is supposed to wait next 24 hours.
*
* @see testable_available_update_checker::cron_execution_offset()
*/
public function test_cron_offset_execution() {
$provider = testable_available_update_checker::instance();
- $provider->fakerecentfetch = time() - 24 * HOURSECS;
- $provider->fakecurrenttimestamp = mktime(1, 45, 02); // 01:45:02 AM
- $this->setExpectedException('testable_available_update_checker_cron_executed');
- $provider->cron();
+
+ // the cron at 01:45 should fetch the data
+ $provider->fakecurrenttimestamp = mktime(1, 45, 02); // 01:45:02 AM today
+ $provider->fakerecentfetch = $provider->fakecurrenttimestamp - 24 * HOURSECS - 1;
+ $executed = false;
+ try {
+ $provider->cron();
+ } catch (testable_available_update_checker_cron_executed $e) {
+ $executed = true;
+ }
+ $this->assertTrue($executed, 'Cron should be executed at 01:45:02 but it was not.');
+
+ // another cron at 06:45 should still consider data as fresh enough
+ $provider->fakerecentfetch = $provider->fakecurrenttimestamp;
+ $provider->fakecurrenttimestamp = mktime(6, 45, 03); // 06:45:03 AM
+ $executed = false;
+ try {
+ $provider->cron();
+ } catch (testable_available_update_checker_cron_executed $e) {
+ $executed = true;
+ }
+ $this->assertFalse($executed, 'Cron should not be executed at 06:45:03 but it was.');
+
+ // the next scheduled execution should happen the next day
+ $provider->fakecurrenttimestamp = $provider->fakerecentfetch + 24 * HOURSECS + 1;
+ $executed = false;
+ try {
+ $provider->cron();
+ } catch (testable_available_update_checker_cron_executed $e) {
+ $executed = true;
+ }
+ $this->assertTrue($executed, 'Cron should be executed the next night but it was not.');
}
public function test_compare_responses_both_empty() {
@@ -503,7 +532,7 @@ protected function cron_execution_offset() {
}
protected function cron_execute() {
- throw new testable_available_update_checker_cron_executed('Cron executed but it should not!');
+ throw new testable_available_update_checker_cron_executed('Cron executed!');
}
}

0 comments on commit 8169e2f

Please sign in to comment.