Commit 45e0868f authored by Manuel Günther's avatar Manuel Günther

Fixed small bug when stopping the scheduler; re-enabled the test (after...

Fixed small bug when stopping the scheduler; re-enabled the test (after leaving it more time to execute).
parent 773d7b52
......@@ -94,6 +94,7 @@ class JobManagerLocal(JobManager):
self.lock()
job, array_job = self._job_and_array(job_id, array_id)
if job is not None:
if job.status == 'executing':
logger.info("Reset job '%s' in the database" % job)
job.status = 'submitted'
......@@ -142,14 +143,14 @@ class JobManagerLocal(JobManager):
self.lock()
# get the files to write to
job, array_job = self._job_and_array(job_id, array_id)
if no_log:
if job is None or no_log:
out, err = None, None
elif array_job:
elif array_job is not None:
out, err = array_job.std_out_file(), array_job.std_err_file()
else:
out, err = job.std_out_file(), job.std_err_file()
log_dir = job.log_dir if not no_log else None
log_dir = job.log_dir if not no_log and job is not None else None
job_id = job.id
array_id = array_job.id if array_job else None
self.unlock()
......
......@@ -78,7 +78,12 @@ class JobManager:
def _job_and_array(self, job_id, array_id = None):
# get the job (and the array job) with the given id(s)
job = self.get_jobs((job_id,))
assert (len(job) == 1)
if len(job) > 1:
logger.error("%d jobs with the same ID '%d' were detected in the database"%(len(job), job_id))
elif not len(job):
logger.warn("Job with ID '%d' was not found in the database."%job_id)
return (None, None)
job = job[0]
unique_id = job.unique
......
......@@ -29,6 +29,7 @@ class GridTKTest(unittest.TestCase):
# make sure that all scheduler jobs are stopped after exiting
if self.scheduler_job:
self.scheduler_job.send_signal(signal.SIGINT)
self.scheduler_job.wait()
# Clean up the mess that we created
import shutil
shutil.rmtree(self.temp_dir)
......@@ -36,8 +37,6 @@ class GridTKTest(unittest.TestCase):
def test01_local(self):
# This test executes all commands of the local grid manager and asserts that everything is fine
raise nose.plugins.skip.SkipTest("[AA, 17.08.2013] Skipping test because it does not work on nightlies until MG is back from holidays")
# first, add some commands to the database
script_1 = pkg_resources.resource_filename('gridtk.tests', 'test_script.sh')
script_2 = pkg_resources.resource_filename('gridtk.tests', 'test_array.sh')
......@@ -79,7 +78,7 @@ class GridTKTest(unittest.TestCase):
self.scheduler_job = subprocess.Popen(['./bin/jman', '--local', '--database', self.database, 'run-scheduler', '--sleep-time', '5', '--parallel', '2'])
# sleep some time to assure that the scheduler was able to start the first job
time.sleep(2)
time.sleep(4)
# ... and kill the scheduler
self.scheduler_job.send_signal(signal.SIGINT)
self.scheduler_job = None
......@@ -100,10 +99,10 @@ class GridTKTest(unittest.TestCase):
jman.main(['./bin/jman', '--local', '--database', self.database, 'resubmit', '--job-id', '1', '--running-jobs'])
# now, start the local execution of the job in a parallel job
self.scheduler_job = subprocess.Popen(['./bin/jman', '--local', '--database', self.database, 'run-scheduler', '--sleep-time', '4', '--parallel', '2'])
self.scheduler_job = subprocess.Popen(['./bin/jman', '--local', '--database', self.database, 'run-scheduler', '--sleep-time', '5', '--parallel', '2'])
# sleep some time to assure that the scheduler was able to finish the first and start the second job
time.sleep(6)
time.sleep(9)
# ... and kill the scheduler
self.scheduler_job.send_signal(signal.SIGINT)
self.scheduler_job = None
......@@ -138,9 +137,9 @@ class GridTKTest(unittest.TestCase):
assert os.path.exists(self.log_dir)
# now, let the scheduler run all jobs
self.scheduler_job = subprocess.Popen(['./bin/jman', '--local', '--database', self.database, 'run-scheduler', '--sleep-time', '0.1', '--parallel', '2', '--die-when-finished'])
self.scheduler_job = subprocess.Popen(['./bin/jman', '--local', '--database', self.database, 'run-scheduler', '--sleep-time', '1', '--parallel', '2', '--die-when-finished'])
# ... and kill the scheduler
time.sleep(3)
time.sleep(10)
assert self.scheduler_job.poll() is not None
self.scheduler_job = None
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment