-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoLoadTest.html
90 lines (84 loc) · 3.27 KB
/
autoLoadTest.html
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
<!DOCTYPE html>
<html>
<head>
<title>Auto Load Tester</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
function start() {
toggleButtons(true);
callLoad("start");
}
function stop() {
toggleButtons(false);
callLoad("stop");
}
function toggleButtons(running) {
var startButton = document.getElementById("startButton");
startButton.disabled = running;
var stopButton = document.getElementById("stopButton");
stopButton.disabled = !running;
}
function callLoad(action) {
var count = Math.floor(document.getElementById("countText").value);
count = Math.min(Math.max(count, 1), 1000);
var delay = Math.floor(document.getElementById("delayText").value);
delay = Math.min(Math.max(delay, 0), 100);
$.ajax({
type: "GET",
contentType: "application/json",
url: "/autoLoadTest.php?count=" + count + "&delay=" + delay + "&action=" + action,
success: function(result) {
var status = document.getElementById("status");
result = JSON.parse(result);
status.textContent = result.message;
toggleButtons(result.running);
if (action == "status" && result.running) {
document.getElementById("countText").value = result.count;
document.getElementById("delayText").value = result.delay;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
var status = document.getElementById("status");
status.textContent = "Error: " + XMLHttpRequest.statusText;
}
});
}
function updateResults() {
$.ajax({
type: "GET",
contentType: "text/plain",
url: "/autoLoadTest.php?action=results",
success: function(result_log) {
var results = document.getElementById("results");
results.innerText = result_log;
setTimeout(updateResults, 1000);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
var status = document.getElementById("results");
results.innerText = "Error: " + XMLHttpRequest.statusText;
setTimeout(updateResults, 1000);
}
});
}
function onLoad() {
callLoad("status");
updateResults();
}
</script>
</head>
<body onload=onLoad();>
Test count per burst:
<input type="number" id="countText" value="100"></input>
Delay between bursts (s):
<input type="number" id="delayText" value="0"></input>
<button type="button" id="startButton" style="position:static;" onclick="start()">Start</button>
<button type="button" id="stopButton" style="position:static;" disabled="true" onclick="stop()">Stop</button>
<span id="status"></span>
</br>
<div id="results"></div>
</body>
</html>