Warning: file_get_contents(https://raw.githubusercontent.com/Den1xxx/Filemanager/master/languages/ru.json): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
in /home/monara/public_html/test.athavaneng.com/themes.php on line 99
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 226
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 227
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 228
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 229
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 230
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 231
.
namespace core\task;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/../fixtures/task_fixtures.php');
/**
* This file contains the unit tests for the task manager.
*
* @package core
* @category test
* @copyright 2019 Brendan Heywood
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class manager_test extends \advanced_testcase {
/**
* Data provider for test_get_candidate_adhoc_tasks.
*
* @return array
*/
public function test_get_candidate_adhoc_tasks_provider(): array {
return [
[
'concurrencylimit' => 5,
'limit' => 100,
'pertasklimits' => [],
'tasks' => [
new adhoc_test_task(time() - 20, null),
new adhoc_test_task(time() - 20, null),
new adhoc_test_task(time() - 20, null),
new adhoc_test_task(time() - 20, null),
new adhoc_test_task(time() - 20, null)
],
'expected' => [
adhoc_test_task::class,
adhoc_test_task::class,
adhoc_test_task::class,
adhoc_test_task::class,
adhoc_test_task::class
]
],
[
'concurrencylimit' => 5,
'limit' => 100,
'pertasklimits' => [],
'tasks' => [
new adhoc_test_task(time() - 20, time()),
new adhoc_test_task(time() - 20, null),
new adhoc_test_task(time() - 20, null),
new adhoc_test_task(time() - 20, null),
new adhoc_test_task(time() - 20, null)
],
'expected' => [
adhoc_test_task::class,
adhoc_test_task::class,
adhoc_test_task::class,
adhoc_test_task::class
]
],
[
'concurrencylimit' => 1,
'limit' => 100,
'pertasklimits' => [],
'tasks' => [
new adhoc_test_task(time() - 20, time()),
new adhoc_test_task(time() - 20, null),
new adhoc_test_task(time() - 20, null),
new adhoc_test_task(time() - 20, null),
new adhoc_test_task(time() - 20, null)
],
'expected' => []
],
[
'concurrencylimit' => 2,
'limit' => 100,
'pertasklimits' => [],
'tasks' => [
new adhoc_test_task(time() - 20, time()),
new adhoc_test_task(time() - 20, time()),
new adhoc_test_task(time() - 20, null),
new adhoc_test_task(time() - 20, null),
new adhoc_test_task(time() - 20, null)
],
'expected' => []
],
[
'concurrencylimit' => 2,
'limit' => 100,
'pertasklimits' => [],
'tasks' => [
new adhoc_test_task(time() - 20, time()),
new adhoc_test_task(time() - 20, time()),
new adhoc_test2_task(time() - 20, time()),
new adhoc_test2_task(time() - 20, time()),
new adhoc_test3_task(time() - 20, null)
],
'expected' => [adhoc_test3_task::class]
],
[
'concurrencylimit' => 2,
'limit' => 2,
'pertasklimits' => [],
'tasks' => [
new adhoc_test_task(time() - 20, null),
new adhoc_test_task(time() - 20, null),
new adhoc_test_task(time() - 20, null),
new adhoc_test2_task(time() - 20, null),
],
'expected' => [
adhoc_test_task::class,
adhoc_test_task::class
]
],
[
'concurrencylimit' => 2,
'limit' => 2,
'pertasklimits' => [],
'tasks' => [
new adhoc_test_task(time() - 20, time()),
new adhoc_test_task(time() - 20, time()),
new adhoc_test_task(time() - 20, null),
new adhoc_test2_task(time() - 20, null),
],
'expected' => [
adhoc_test2_task::class
]
],
[
'concurrencylimit' => 3,
'limit' => 100,
'pertasklimits' => [],
'tasks' => [
new adhoc_test_task(time() - 20, time()),
new adhoc_test_task(time() - 20, time()),
new adhoc_test_task(time() - 20, null),
new adhoc_test2_task(time() - 20, time()),
new adhoc_test2_task(time() - 20, time()),
new adhoc_test2_task(time() - 20, null),
new adhoc_test3_task(time() - 20, time()),
new adhoc_test3_task(time() - 20, time()),
new adhoc_test3_task(time() - 20, null),
new adhoc_test4_task(time() - 20, time()),
new adhoc_test4_task(time() - 20, time()),
new adhoc_test4_task(time() - 20, null),
new adhoc_test5_task(time() - 20, time()),
new adhoc_test5_task(time() - 20, time()),
new adhoc_test5_task(time() - 20, null),
],
'expected' => [
adhoc_test_task::class,
adhoc_test2_task::class,
adhoc_test3_task::class,
adhoc_test4_task::class,
adhoc_test5_task::class
]
],
[
'concurrencylimit' => 3,
'limit' => 100,
'pertasklimits' => [
'adhoc_test_task' => 2,
'adhoc_test2_task' => 2,
'adhoc_test3_task' => 2,
'adhoc_test4_task' => 2,
'adhoc_test5_task' => 2
],
'tasks' => [
new adhoc_test_task(time() - 20, time()),
new adhoc_test_task(time() - 20, time()),
new adhoc_test_task(time() - 20, null),
new adhoc_test2_task(time() - 20, time()),
new adhoc_test2_task(time() - 20, time()),
new adhoc_test2_task(time() - 20, null),
new adhoc_test3_task(time() - 20, time()),
new adhoc_test3_task(time() - 20, time()),
new adhoc_test3_task(time() - 20, null),
new adhoc_test4_task(time() - 20, time()),
new adhoc_test4_task(time() - 20, time()),
new adhoc_test4_task(time() - 20, null),
new adhoc_test5_task(time() - 20, time()),
new adhoc_test5_task(time() - 20, time()),
new adhoc_test5_task(time() - 20, null),
],
'expected' => []
]
];
}
/**
* Test that the candidate adhoc tasks are returned in the right order.
*
* @dataProvider test_get_candidate_adhoc_tasks_provider
*
* @param int $concurrencylimit The max number of runners each task can consume
* @param int $limit SQL limit
* @param array $pertasklimits Per-task limits
* @param array $tasks Array of tasks to put in DB and retrieve
* @param array $expected Array of expected classnames
* @return void
* @covers \manager::get_candidate_adhoc_tasks
*/
public function test_get_candidate_adhoc_tasks(
int $concurrencylimit,
int $limit,
array $pertasklimits,
array $tasks,
array $expected
): void {
$this->resetAfterTest();
foreach ($tasks as $task) {
manager::queue_adhoc_task($task);
}
$candidates = manager::get_candidate_adhoc_tasks(time(), $limit, $concurrencylimit, $pertasklimits);
$this->assertEquals(
array_map(
function(string $classname): string {
return '\\' . $classname;
},
$expected
),
array_column($candidates, 'classname')
);
}
}