Skip to content
Snippets Groups Projects
Commit 93ba0dd3 authored by Daniel Brown's avatar Daniel Brown
Browse files

added watcher thread to manage returning gracefully from test exceptions and starting new tests

parent 9ee26fa6
Branches
No related tags found
No related merge requests found
......@@ -54,7 +54,7 @@ class FinesseTestProcess(Thread):
def __init__(self, TEST_DIR, BASE_DIR, git_commit,
run_fast=False, suites=[], test_id="0",
git_bin="",emails="", nobuild=False,*args, **kqwargs):
git_bin="",emails="", nobuild=True,*args, **kqwargs):
Thread.__init__(self)
self.git_commit = git_commit
......@@ -104,7 +104,10 @@ class FinesseTestProcess(Thread):
self.GIT_BIN = git_bin
def percent_done(self):
return 100.0*float(self.done_files)/float(self.total_files)
if self.total_kats == 0:
return 0.0
else:
return 100.0*float(self.done_kats)/float(self.total_kats)
def get_version(self):
return self.git_commit
......@@ -283,6 +286,7 @@ class FinesseTestProcess(Thread):
output_differences[suite][out] = (ref_arr[ix], out_arr[ix], np.max(rel_diff))
os.chdir(BASE_DIR)
if not os.path.exists("reports"):
os.mkdir("reports")
......@@ -347,16 +351,6 @@ class FinesseTestProcess(Thread):
finally:
finished_test = True
# once done check if any other tests need to be ran
#schedule_lock.acquire()
#if len(scheduled_tests) > 0:
# current_test = scheduled_tests.pop(0)
# current_test.start()
#else:
# current_test = None
#schedule_lock.release()
if __name__ == "__main__":
......
......@@ -9,7 +9,8 @@ from flask import render_template
from datetime import datetime
from collections import namedtuple
from pykat.testing import utils
from pykat.testing import test as finesse_test
import shutil
from pykat.testing.web import app
import os
......@@ -20,11 +21,59 @@ test_id = 0
current_test = None
scheduled_tests = []
schedule_lock = Lock()
watcher = None
print "loading web interface"
class FinesseProcessWatcher(Thread):
process_to_watch = None
def __init__(self,*args, **kqwargs):
Thread.__init__(self)
def setProcessToWatch(self, process):
print type(process)
#if type(self.process_to_watch) is not finesse_test.FinesseTestProcess:
# raise Exception("Tried to watch something which wasn't a FinesseTestProcess")
self.process_to_watch = process
def run(self):
global schedule_lock,current_test,scheduled_tests, watcher
if self.process_to_watch is None:
return
#if type(self.process_to_watch) is not finesse_test.FinesseTestProcess:
# raise Exception("Tried to watch something which wasn't a FinesseTestProcess")
print "Watcher is watching", self.process_to_watch
self.process_to_watch.join()
print "Watcher is continuing"
# once done check if any other tests need to be ran
schedule_lock.acquire()
if len(scheduled_tests) > 0:
print "Watcher starting next test"
current_test = scheduled_tests.pop(0)
watcher = FinesseProcessWatcher()
watcher.setProcessToWatch(current_test)
watcher.start()
current_test.start()
else:
print "Watcher found no more tests to run"
current_test = None
schedule_lock.release()
@app.route('/')
def hello_world():
def home_page():
return render_template("finesse_test.html")
@app.route('/finesse/start_test', methods=["POST"])
......@@ -38,15 +87,37 @@ def finesse_start_test():
git_commit = request.json['git_commit']
test = FinesseTestProcess(git_commit, test_id)
print app.instance_path
TEST_OUTPUT_PATH = os.path.join(app.instance_path, "tests")
if not os.path.exists(TEST_OUTPUT_PATH):
os.mkdir(TEST_OUTPUT_PATH)
TEST_RUN_PATH = os.path.join(TEST_OUTPUT_PATH, str(test_id))
print TEST_RUN_PATH
if os.path.exists(TEST_RUN_PATH):
shutil.rmtree(TEST_RUN_PATH)
os.mkdir(TEST_RUN_PATH)
test = finesse_test.FinesseTestProcess(os.path.join(app.instance_path, "finesse_test"),
TEST_RUN_PATH,
git_commit,
run_fast=False, suites=[], test_id=test_id,
emails="", nobuild=True)
# check if anything is running and if it
# isn't start this test off
if current_test is None:
print "running test"
current_test = test
watcher = FinesseProcessWatcher()
watcher.setProcessToWatch(test)
watcher.start()
test.start()
else:
print "queuing test"
scheduled_tests.append(test)
......@@ -112,27 +183,3 @@ def finesse_get_log(count):
return jsonify(logs=log2send)
\ No newline at end of file
class FinesseTestProcessRun():
def __init__(self, init_class=FinesseTestProcess):
self.init_class = init_class
print "Init.."
def start(self, *args, **kwargs):
print "Calling..."
fjp = self.init_class(*args, **kwargs)
print '%s threaded process beginning.' % fjp.__class__.__name__
print fjp.get_progress()
fjp.start()
while fjp.is_alive():
sleep(1)
print fjp.get_progress()
print fjp.get_progress()
print '%s threaded process complete. Now exiting.' % fjp.__class__.__name__
\ No newline at end of file
......@@ -20,6 +20,9 @@ def start(instance_path,port=5000, debug=True):
from pykat.testing.web import app
if(app.instance_path!=instance_path):
raise Exception("Instance path of Flask app didn't match the requested value")
# load up the actual interface code
import pykat.testing.web.web_interface
......@@ -31,6 +34,11 @@ def start(instance_path,port=5000, debug=True):
# get the latest version for logs etc.
utils.git("--git-dir ./finesse_src/.git pull")
# need local copy of test
if not os.path.exists("./finesse_test"):
print "finesse test folder didn't exist, cloning now..."
utils.git("clone git://gitmaster.atlas.aei.uni-hannover.de/finesse/test.git finesse_test")
app.secret_key = os.urandom(24)
app.run(debug=debug, port=int(port))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment