-
Notifications
You must be signed in to change notification settings - Fork 30
/
aborttest.php
99 lines (82 loc) · 3.1 KB
/
aborttest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?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/>.
/**
* Performs a request abort test
*
* @package tool_heartbeat
* @copyright 2019 Brendan Heywood <brendan@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('NO_OUTPUT_BUFFERING', true);
require(__DIR__ . '/../../../config.php');
require_login();
$stage = optional_param('stage', 1, PARAM_NUMBER);
$ignoreabort = optional_param('ignoreabort', 0, PARAM_NUMBER);
if ($ignoreabort) {
ignore_user_abort(true);
// Worst case it should die in 5 seconds.
set_time_limit(5);
}
$syscontext = context_system::instance();
$url = new moodle_url('/admin/tool/heartbeat/aborttest.php');
$PAGE->set_url($url);
$PAGE->set_context($syscontext);
$PAGE->set_pagelayout('standard');
$PAGE->set_cacheable(false);
$url->params(array('stage' => 2));
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('testabort', 'tool_heartbeat'));
echo get_string('testaborthelp', 'tool_heartbeat');
echo "<h3>Stage: $stage</h3>";
if ($stage == 2) {
$progress = $SESSION->abortprogress;
if ($progress > 0 && $progress < 100) {
echo $OUTPUT->notification("Yay! the request was correctly aborted at {$progress}%", \core\output\notification::NOTIFY_SUCCESS);
} else {
echo $OUTPUT->notification("Doh! the request was not aborted: {$progress}%", \core\output\notification::NOTIFY_ERROR);
}
echo "<p><a class='btn btn-primary' href='aborttest.php'>Start again</a></p>";
echo "<p><a class='btn btn-danger' href='aborttest.php?ignoreabort=1'>Start again with ignore_user_abort</a></p>";
echo $OUTPUT->footer();
}
if ($stage == 1) {
echo <<<EOF
<p>This should show a moving progress bar, but after 1 seconds the page should reload and it should NOT get to 100%.</p>
<script>
setTimeout(function(){
window.stop();
location.href = '{$url->out()}';
},1000);
</script>
EOF;
$progressbar = new progress_bar();
$progressbar->create();
echo $OUTPUT->footer();
$SESSION->abortprogress = 0;
$totalseconds = 10;
$progressbar->update_full(0, '0%');
for ($c = 1; $c <= 100; $c += .1) {
usleep(10000);
$progressbar->update_full($c, sprintf('%.1f%%', $c));
$SESSION->abortprogress = $c;
if (connection_status() != CONNECTION_NORMAL) {
// @codingStandardsIgnoreStart
error_log("Aborting stage 1 at $c %");
// @codingStandardsIgnoreEnd
}
}
$SESSION->abortprogress = 100;
}