Skip to content

Commit

Permalink
Merge pull request locustio#13 from pancaprima/prima/b_timer
Browse files Browse the repository at this point in the history
Prima bugfix timer doesn't work smoothly
  • Loading branch information
erlanggakrisnamukti authored Oct 17, 2017
2 parents b25b3f8 + a9e4d13 commit 498898e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
6 changes: 6 additions & 0 deletions locust/static/locust.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ function updateStats() {
$('#stats tbody').empty();
$('#errors tbody').empty();

//Handle if user request to reset stats
if(report.total_run_time < runTime ) {
runTime = report.total_run_time;
$("#run_time").html(String(runTime).toHHMMSS())
}

alternate = false;

totalRow = report.stats.pop()
Expand Down
47 changes: 21 additions & 26 deletions locust/static/timer.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
var sec = 0;
var clicked = false;
var runTime = 0;
var isTestRunning = false;

$(".stop-clock").click(function (event) {
clicked = false;
$(".stop-timer").click(function (event) {
isTestRunning = false;
});

$(".start-clock").click(function (event) {
clicked = true;
sec = 0;
$(".start-timer").click(function (event) {
runTime = 0;
});

function updateTimer() {
$.get('/stats/requests', function (data) {
report = JSON.parse(data);
var time;
var totalRunTimeInSeconds = report.total_run_time;

if (totalRunTimeInSeconds >= sec) {
time = totalRunTimeInSeconds;
} else {
time = sec;
}
$("#run_time").html(String(time).toHHMMSS());
if (clicked) {
sec++;
}
setTimeout(updateTimer, 1000);
});
if ( runTime == 0 ) {
$.get('/stats/requests', function (data) {
report = JSON.parse(data);
runTime = report.total_run_time;
isTestRunning = (report.state == "stopped") ? false : true;
//update the UI of timer to the last/current runtime
$("#run_time").html(String(runTime).toHHMMSS())
if (isTestRunning) ++runTime
else runTime = 0
})
} else if (isTestRunning) {
$("#run_time").html(String(runTime++).toHHMMSS());
}
}

updateTimer();
setInterval(updateTimer, 1000);

String.prototype.toHHMMSS = function () {
var sec_num = parseInt(this, 10);
Expand All @@ -48,4 +43,4 @@ String.prototype.toHHMMSS = function () {
}
var time = hours + ':' + minutes + ':' + seconds;
return time;
};
};
8 changes: 4 additions & 4 deletions locust/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<div class="value"><span id="run_time"></span>{{ run_time }}</div>
</div>
<div class="top_box box_stop box_running" id="box_stop">
<a href="/stop" class="stop-button stop-clock"><i></i>STOP</a>
<a href="/stop" class="stop-button stop-timer"><i></i>STOP</a>
<a href="/stats/reset" class="reset-button">Reset<br>Stats</a>
</div>
</div>
Expand All @@ -63,7 +63,7 @@
</div>
<div class="padder">
<h2>Start new Locust swarm</h2>
<form action="/swarm" method="POST" id="swarm_form" class="start-clock">
<form action="/swarm" method="POST" id="swarm_form" class="start-timer">
<input type="text" name="locust_count" id="locust_count" class="val" /><br>
<label for="hatch_rate">Hatch rate <span style="color:#8a8a8a;">(users spawned/second)</span></label>
<input type="text" name="hatch_rate" id="hatch_rate" class="val" /><br>
Expand Down Expand Up @@ -104,7 +104,7 @@ <h2>Change the locust count</h2>
</div>
<div class="padder">
<h2>Ramping</h2>
<form action="/ramp" method="POST" id="ramp_form" class="start-clock">
<form action="/ramp" method="POST" id="ramp_form" class="start-timer">
<div style="float:left;">
<label for="init_count" title="This is the number of initial number of locusts that will be spawned. Pick a number you know can be handled.">Initial number of clients</label>
<input type="text" name="init_count" id="init_count" class="val" /><br>
Expand Down Expand Up @@ -291,8 +291,8 @@ <h1>Version</h1>
]]>
</script>
<script type="text/javascript" src="/static/chart.js?v={{ version }}"></script>
<script type="text/javascript" src="/static/locust.js?v={{ version }}"></script>
<script type="text/javascript" src="/static/timer.js"></script>
<script type="text/javascript" src="/static/locust.js?v={{ version }}"></script>

</body>
</html>

0 comments on commit 498898e

Please sign in to comment.