-
Notifications
You must be signed in to change notification settings - Fork 0
/
catalogLoadTest.html
97 lines (86 loc) · 3.49 KB
/
catalogLoadTest.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
91
92
93
94
95
96
97
<!DOCTYPE html>
<html>
<head>
<title>Catalog API 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() {
var status = document.getElementById("status");
status.textContent = "Running...";
var startButton = document.getElementById("startButton");
startButton.disabled = true;
var stopButton = document.getElementById("stopButton");
stopButton.disabled = false;
callLoad();
}
function callLoad() {
if (!isActive()) {
return;
}
var table = document.getElementById("resultsTable");
var count = Math.floor(document.getElementById("countText").value);
count = Math.min(Math.max(count, 1), 1000);
$.ajax({
type: "GET",
contentType: "application/json",
url: "/ajaxCatalogLoadTest.php?count=" + count,
success: function(result) {
if (!isActive()) {
return;
}
result = JSON.parse(result);
var row = table.insertRow();
var successCell = row.insertCell();
var text = document.createTextNode("success count: " + result.success);
successCell.appendChild(text);
var failCell = row.insertCell();
text = document.createTextNode("failure count: " + result.fail);
failCell.appendChild(text);
var timeCell = row.insertCell();
text = document.createTextNode("time (ms): " + result.time);
timeCell.appendChild(text);
var delay = Math.floor(document.getElementById("delayText").value);
delay = Math.min(Math.max(delay, 1), 100);
setTimeout(callLoad, delay * 1000);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (!isActive()) {
return;
}
var row = table.insertRow();
var cell = row.insertCell();
var text = document.createTextNode("failure: " + XMLHttpRequest.responseText);
cell.appendChild(text);
stop();
}
});
}
function isActive() {
var stopButton = document.getElementById("stopButton");
return !stopButton.disabled;
}
function stop() {
var status = document.getElementById("status");
status.textContent = "";
var startButton = document.getElementById("startButton");
startButton.disabled = false;
var stopButton = document.getElementById("stopButton");
stopButton.disabled = true;
}
</script>
</head>
<body>
Test count per burst:
<input type="number" id="countText" value="100"></input>
Delay between bursts (s):
<input type="number" id="delayText" value="2"></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>
<table id="resultsTable"></table>
</body>
</html>