mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
Merge branch 'MDL-66475-39' of git://github.com/paulholden/moodle into MOODLE_39_STABLE
This commit is contained in:
commit
a5d64155ad
1 changed files with 16 additions and 16 deletions
|
@ -433,11 +433,12 @@ class task_database_logger_testcase extends advanced_testcase {
|
||||||
|
|
||||||
$this->resetAfterTest();
|
$this->resetAfterTest();
|
||||||
|
|
||||||
// Create sample log data - 2 tasks, once per hour for 3 days.
|
// Calculate date to be used for logs, starting from current time rounded down to nearest hour.
|
||||||
$date = new DateTime();
|
$date = new DateTime();
|
||||||
$date->setTime($date->format('G'), 0);
|
$date->setTime($date->format('G'), 0);
|
||||||
$baselogtime = $date->getTimestamp();
|
$baselogtime = $date->getTimestamp();
|
||||||
|
|
||||||
|
// Create sample log data - 2 tasks, once per hour for 3 days.
|
||||||
for ($i = 0; $i < 3 * 24; $i++) {
|
for ($i = 0; $i < 3 * 24; $i++) {
|
||||||
$task = new \core\task\cache_cron_task();
|
$task = new \core\task\cache_cron_task();
|
||||||
$logpath = __FILE__;
|
$logpath = __FILE__;
|
||||||
|
@ -456,36 +457,35 @@ class task_database_logger_testcase extends advanced_testcase {
|
||||||
$this->assertEquals(72, $DB->count_records('task_log', ['classname' => \core\task\badges_cron_task::class]));
|
$this->assertEquals(72, $DB->count_records('task_log', ['classname' => \core\task\badges_cron_task::class]));
|
||||||
|
|
||||||
// Note: We set the retention time to a period like DAYSECS minus an adjustment.
|
// Note: We set the retention time to a period like DAYSECS minus an adjustment.
|
||||||
// The adjustment is to account for the time taken during setup.
|
// The adjustment is to account for the difference between current time and baselogtime.
|
||||||
|
|
||||||
// With a retention period of 2 * DAYSECS, there should only be 94-96 left.
|
// With a retention period of 2 * DAYSECS, there should only be 96 left.
|
||||||
// The run count is a higher number so it will have no effect.
|
// The run count is a higher number so it will have no effect.
|
||||||
set_config('task_logretention', (2 * DAYSECS) - (time() - $baselogtime));
|
set_config('task_logretention', time() - ($baselogtime - (2 * DAYSECS)) - 1);
|
||||||
set_config('task_logretainruns', 50);
|
set_config('task_logretainruns', 50);
|
||||||
\core\task\database_logger::cleanup();
|
\core\task\database_logger::cleanup();
|
||||||
$this->assertGreaterThanOrEqual(94, $DB->count_records('task_log'));
|
|
||||||
$this->assertLessThanOrEqual(96, $DB->count_records('task_log'));
|
|
||||||
$this->assertGreaterThanOrEqual(47, $DB->count_records('task_log', ['classname' => \core\task\cache_cron_task::class]));
|
|
||||||
$this->assertLessThanOrEqual(48, $DB->count_records('task_log', ['classname' => \core\task\cache_cron_task::class]));
|
|
||||||
$this->assertGreaterThanOrEqual(47, $DB->count_records('task_log', ['classname' => \core\task\badges_cron_task::class]));
|
|
||||||
$this->assertLessThanOrEqual(48, $DB->count_records('task_log', ['classname' => \core\task\badges_cron_task::class]));
|
|
||||||
|
|
||||||
// We should retain the most recent 48 so the oldest will be no more than 48 hours old.
|
$this->assertEquals(96, $DB->count_records('task_log'));
|
||||||
$oldest = $DB->get_records('task_log', [], 'timestart DESC', 'timestart', 0, 1);
|
$this->assertEquals(48, $DB->count_records('task_log', ['classname' => \core\task\cache_cron_task::class]));
|
||||||
|
$this->assertEquals(48, $DB->count_records('task_log', ['classname' => \core\task\badges_cron_task::class]));
|
||||||
|
|
||||||
|
// We should retain the most recent 48 of each task, so the oldest will be 47 hours old.
|
||||||
|
$oldest = $DB->get_records('task_log', [], 'timestart ASC', 'timestart', 0, 1);
|
||||||
$oldest = reset($oldest);
|
$oldest = reset($oldest);
|
||||||
$this->assertGreaterThan(time() - (48 * DAYSECS), $oldest->timestart);
|
$this->assertEquals($baselogtime - (47 * HOURSECS), $oldest->timestart);
|
||||||
|
|
||||||
// Reducing the retain runs count to 10 should reduce the total logs to 20, overriding the time constraint.
|
// Reducing the retain runs count to 10 should reduce the total logs to 20, overriding the time constraint.
|
||||||
set_config('task_logretainruns', 10);
|
set_config('task_logretainruns', 10);
|
||||||
\core\task\database_logger::cleanup();
|
\core\task\database_logger::cleanup();
|
||||||
|
|
||||||
$this->assertEquals(20, $DB->count_records('task_log'));
|
$this->assertEquals(20, $DB->count_records('task_log'));
|
||||||
$this->assertEquals(10, $DB->count_records('task_log', ['classname' => \core\task\cache_cron_task::class]));
|
$this->assertEquals(10, $DB->count_records('task_log', ['classname' => \core\task\cache_cron_task::class]));
|
||||||
$this->assertEquals(10, $DB->count_records('task_log', ['classname' => \core\task\badges_cron_task::class]));
|
$this->assertEquals(10, $DB->count_records('task_log', ['classname' => \core\task\badges_cron_task::class]));
|
||||||
|
|
||||||
// We should retain the most recent 10 so the oldeste will be no more than 10 hours old.
|
// We should retain the most recent 10 of each task, so the oldest will be 9 hours old.
|
||||||
$oldest = $DB->get_records('task_log', [], 'timestart DESC', 'timestart', 0, 1);
|
$oldest = $DB->get_records('task_log', [], 'timestart ASC', 'timestart', 0, 1);
|
||||||
$oldest = reset($oldest);
|
$oldest = reset($oldest);
|
||||||
$this->assertGreaterThan(time() - (10 * DAYSECS), $oldest->timestart);
|
$this->assertEquals($baselogtime - (9 * HOURSECS), $oldest->timestart);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue