diff --git a/mod_test/controllers.py b/mod_test/controllers.py index 82eb98d3..223b70c8 100644 --- a/mod_test/controllers.py +++ b/mod_test/controllers.py @@ -8,6 +8,8 @@ url_for) from sqlalchemy import and_, func from sqlalchemy.sql import label +from sqlalchemy import func + from decorators import template_renderer from exceptions import TestNotFoundException @@ -447,3 +449,44 @@ def stop_test(test_id): g.db.commit() g.log.info(f"test with id: {test_id} stopped") return redirect(url_for('.by_id', test_id=test.id)) + + +@mod_regression.route('/progress', methods=['GET']) +def progress(): + """ + Get regression test progress stats + Optional: filter by run or sample + Default: global progress + """ + run = request.args.get('run') + + total = RegressionTest.query.filter(RegressionTest.active == True).count() + done = 0 + try: + if run: + if hasattr(TestResultFile, 'run_uuid'): + done = TestResultFile.query.filter( + TestResultFile.run_uuid == run, + TestResultFile.got.isnot(None) + ).count() + elif hasattr(TestResultFile, 'run_id'): + done = TestResultFile.query.filter( + TestResultFile.run_id == run, + TestResultFile.got.isnot(None) + ).count() + else: + done = TestResultFile.query.filter( + TestResultFile.got.isnot(None) + ).distinct(TestResultFile.regression_test_id).count() + + except Exception: + done = TestResultFile.query.filter(TestResultFile.got.isnot(None)).count() + + pct = 100 if total == 0 else int((done / total) * 100) + + return jsonify({ + 'status': 'success', + 'total': total, + 'completed': done, + 'percent': pct + }) \ No newline at end of file diff --git a/templates/test/by_id.html b/templates/test/by_id.html index 8a92167d..96116d59 100644 --- a/templates/test/by_id.html +++ b/templates/test/by_id.html @@ -52,6 +52,15 @@

Test progress for {{ title }}

{%- endfor %}
+ + + + {% if test.progress|length > 0 %} {% if test.finished %} @@ -178,6 +187,25 @@
There are no tests executed in this category.
window.location.reload(); } val = data.progress_array; + + if (typeof data.progress_percent !== 'undefined') { + try { + var pct = parseInt(data.progress_percent,10); + var total = parseInt(data.total_tests || 0,10); + var done = parseInt(data.completed_tests || 0, 10); + + if(total>0 || pct>0){ + $('#testing-progress-container').show(); + $('#testing-progress-bar').attr('value', pct); + $('#testing-progress-label').text('Testing: ' + done + '/' + total + ' (' + pct + '%)'); + } else{ + $('#testing-progress-container').hide(); + } + } + catch(e){ + console.log('progress update error',e); + } + } if (testprogress === 0 && val.length !== 0) { window.location.reload(); }