Skip to content

Commit

Permalink
fixup! MDL-70854 core: Alters running tasks page to show progress bars
Browse files Browse the repository at this point in the history
  • Loading branch information
marxjohnson committed May 10, 2024
1 parent b7ec423 commit 679d083
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
22 changes: 22 additions & 0 deletions admin/tool/task/tests/behat/running_tasks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,25 @@ Feature: See running scheduled tasks
And I should see "2 days" in the "core\task\asynchronous_restore_task" "table_row"
And I should see "c69335460f7f" in the "core\task\asynchronous_restore_task" "table_row"
And I should see "1916" in the "core\task\asynchronous_restore_task" "table_row"

@javascript
Scenario: If a task with a stored progress bar is running, I should be able to observe the progress.
Given the following config values are set as admin:
| progresspollinterval | 1 |
And the following "tool_task > scheduled tasks" exist:
| classname | seconds | hostname | pid |
| \core\task\delete_unconfirmed_users_task | 120 | c69335460f7f | 1917 |
And the following "stored progress bars" exist:
| idnumber | percent |
| core_task_delete_unconfirmed_users_task | 50.00 |
And I navigate to "Server > Tasks > Tasks running now" in site administration
And I should see "2 mins" in the "Delete unconfirmed users" "table_row"
And I should see "c69335460f7f" in the "Delete unconfirmed users" "table_row"
And I should see "1917" in the "Delete unconfirmed users" "table_row"
And I should see "50.0%" in the "Delete unconfirmed users" "table_row"

When I set the stored progress bar "core_task_delete_unconfirmed_users_task" to "75.00"
# Wait for the progress polling.
And I wait "1" seconds
Then I should not see "50.0%" in the "Delete unconfirmed users" "table_row"
And I should see "75.0%" in the "Delete unconfirmed users" "table_row"
5 changes: 5 additions & 0 deletions lib/behat/classes/behat_core_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ protected function get_creatable_entities(): array {
'required' => ['subject', 'userfrom', 'userto'],
'switchids' => ['userfrom' => 'userfromid', 'userto' => 'usertoid'],
],
'stored progress bars' => [
'singular' => 'stored progress bar',
'datagenerator' => 'stored_progress_bar',
'required' => ['idnumber'],
],
];

return $entities;
Expand Down
16 changes: 16 additions & 0 deletions lib/testing/generator/data_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,22 @@ public function create_stored_progress(
return $record;
}

/**
* Generate a stored progress record from an array of fields.
*
* For use as a behat createable entity. Use {@see self::create_stored_progress()} if calling directly.
*/
public function create_stored_progress_bar(array $data): void {
$this->create_stored_progress(
$data['idnumber'] ?? null,
$data['timestart'] ?? null,
$data['lastupdate'] ?? null,
$data['percent'] ?? 0.00,
$data['message'] ?? null,
$data['haserrored'] ?? false,
);
}

/**
* Gets a default generator for a given component.
*
Expand Down
16 changes: 16 additions & 0 deletions lib/tests/behat/behat_general.php
Original file line number Diff line number Diff line change
Expand Up @@ -2400,4 +2400,20 @@ public function the_page_title_should_contain(string $title): void {
);
}
}

/**
* Update a stored progress bar.
*
* @Given I set the stored progress bar :idnumber to :percent
* @param string $idnumber The unique idnumber of the stored progress bar.
* @param float $percent The value to update the progress bar to.
*/
public function i_set_the_stored_progress_bar_to(string $idnumber, float $percent): void {
$progress = \core\stored_progress_bar::get_by_idnumber($idnumber);
if (!$progress) {
throw new invalid_parameter_exception('No progress bar with idnumber ' . $idnumber . 'found.');
}
$progress->auto_update(false);
$progress->update_full($percent, '');
}
}

0 comments on commit 679d083

Please sign in to comment.