From 4605729d45599ca5a34015d380ec6dfd30ff874e Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Fri, 13 Mar 2026 12:36:27 +0000 Subject: [PATCH] MDL-88211 backup: remove redundant usage of task manager from tests. The asynchronouse backup/restore tests are only concerned with testing the implementation of the accompanying task class directly. When they try to do so at a distance via the task manager API they introduce random failures by failing to account for different queued tasks that come from other components (e.g. Workplace). --- backup/tests/async_backup_test.php | 23 +++-------------------- backup/tests/async_restore_test.php | 20 ++------------------ 2 files changed, 5 insertions(+), 38 deletions(-) diff --git a/backup/tests/async_backup_test.php b/backup/tests/async_backup_test.php index 23d8b964e11..d4c48668826 100644 --- a/backup/tests/async_backup_test.php +++ b/backup/tests/async_backup_test.php @@ -107,17 +107,12 @@ final class async_backup_test extends \advanced_testcase { $asynctask = new \core\task\asynchronous_backup_task(); $asynctask->set_custom_data(['backupid' => $backupid]); $asynctask->set_userid($USER->id); - \core\task\manager::queue_adhoc_task($asynctask); // We are expecting trace output during this test. $this->expectOutputRegex("/$backupid/"); // Execute adhoc task. - $now = time(); - $task = \core\task\manager::get_next_adhoc_task($now); - $this->assertInstanceOf('\\core\\task\\asynchronous_backup_task', $task); - $task->execute(); - \core\task\manager::adhoc_task_complete($task); + $asynctask->execute(); $postbackuprec = $DB->get_record('backup_controllers', ['backupid' => $backupid]); @@ -151,13 +146,9 @@ final class async_backup_test extends \advanced_testcase { // Create the adhoc task. $asynctask = new \core\task\asynchronous_backup_task(); $asynctask->set_custom_data(['backupid' => $backupid]); - \core\task\manager::queue_adhoc_task($asynctask); // Execute adhoc task. - $now = time(); - $task = \core\task\manager::get_next_adhoc_task($now); - $task->execute(); - \core\task\manager::adhoc_task_complete($task); + $asynctask->execute(); $postbackuprec = $DB->get_record('backup_controllers', ['backupid' => $backupid]); @@ -241,19 +232,11 @@ final class async_backup_test extends \advanced_testcase { // Now queue an adhoc task and check it handles and completes gracefully. $asynctask = new \core\task\asynchronous_backup_task(); $asynctask->set_custom_data(array('backupid' => $backupid)); - \core\task\manager::queue_adhoc_task($asynctask); // We are expecting a specific message output during this test. $this->expectOutputRegex('/invalid controller/'); // Execute adhoc task. - $now = time(); - $task = \core\task\manager::get_next_adhoc_task($now); - $this->assertInstanceOf('\\core\\task\\asynchronous_backup_task', $task); - $task->execute(); - \core\task\manager::adhoc_task_complete($task); - - // Check the task record is removed. - $this->assertEquals(0, $DB->count_records('task_adhoc')); + $asynctask->execute(); } } diff --git a/backup/tests/async_restore_test.php b/backup/tests/async_restore_test.php index ec7558e1ea8..ff98863d65a 100644 --- a/backup/tests/async_restore_test.php +++ b/backup/tests/async_restore_test.php @@ -223,20 +223,12 @@ final class async_restore_test extends \advanced_testcase { // Create the adhoc task. $asynctask = new \core\task\asynchronous_restore_task(); $asynctask->set_custom_data(['backupid' => $restoreid]); - \core\task\manager::queue_adhoc_task($asynctask); // We are expecting a specific message output during this test. $this->expectOutputRegex('/invalid controller/'); // Execute adhoc task. - $now = time(); - $task = \core\task\manager::get_next_adhoc_task($now); - $this->assertInstanceOf('\\core\\task\\asynchronous_restore_task', $task); - $task->execute(); - \core\task\manager::adhoc_task_complete($task); - - // Check the task record is removed. - $this->assertEquals(0, $DB->count_records('task_adhoc')); + $asynctask->execute(); // Now delete the record and confirm an entirely missing controller is handled. $DB->delete_records('backup_controllers'); @@ -244,19 +236,11 @@ final class async_restore_test extends \advanced_testcase { // Create the adhoc task. $asynctask = new \core\task\asynchronous_restore_task(); $asynctask->set_custom_data(['backupid' => $restoreid]); - \core\task\manager::queue_adhoc_task($asynctask); // We are expecting a specific message output during this test. $this->expectOutputRegex('/Unable to find restore controller/'); // Execute adhoc task. - $now = time(); - $task = \core\task\manager::get_next_adhoc_task($now); - $this->assertInstanceOf('\\core\\task\\asynchronous_restore_task', $task); - $task->execute(); - \core\task\manager::adhoc_task_complete($task); - - // Check the task record is removed. - $this->assertEquals(0, $DB->count_records('task_adhoc')); + $asynctask->execute(); } }