Skip to content
Snippets Groups Projects
Commit 7cd5c035 authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

[backend] More tests

parent e5184e9d
No related branches found
No related tags found
1 merge request!194Scheduler
Pipeline #
......@@ -1289,4 +1289,123 @@ class Scheduling(BaseBackendTestCase):
# time and we'll optimise correctly and only run one of them. The other
# is updated as the blocking experiment is executed.
pass
current_stats = HourlyStatistics.objects.count()
fullname = 'user/user/single/1/single'
xp = Experiment.objects.get(name=fullname.split(os.sep)[-1])
xpc = xp.fork(name='single_copy')
# schedules the experiment and check it
xp.schedule()
xpc.schedule()
# schedules the first runnable block
assert xp.blocks.first().job.runnable_date is not None
assert xp.blocks.last().job.runnable_date is None
assert xpc.blocks.first().job.runnable_date is None
assert xpc.blocks.last().job.runnable_date is None
schedule()
assigned_splits = JobSplit.objects.filter(worker__isnull=False)
worker = Worker.objects.get()
self.assertEqual(assigned_splits.count(), 1)
split = assigned_splits.first()
self.assertEqual(split.job.block.experiment, xp)
self.assertEqual(split.job.block.name, 'echo')
self.assertEqual(split.worker, worker)
self.assertEqual(worker.name, qsetup.HOSTNAME)
self.assertEqual(worker.available_cores(), qsetup.CORES)
# checks the jobs are connected one to the other across experiments
self.assertEqual(xp.blocks.first().job.child.block.experiment, xpc)
self.assertEqual(xp.blocks.last().job.child.block.experiment, xpc)
# simulate job start on worker
split.start()
self.assertEqual(split.job.status, Job.PROCESSING)
self.assertEqual(split.job.block.status, Block.PROCESSING)
self.assertEqual(split.job.block.experiment.status, Experiment.RUNNING)
self.assertEqual(worker.available_cores(), qsetup.CORES-1)
# check child
self.assertEqual(xpc.blocks.first().job.status, Job.PROCESSING)
self.assertEqual(xpc.blocks.first().status, Block.PROCESSING)
'''
self.assertEqual(xpc.blocks.first().experiment.status, Experiment.RUNNING)
# no job can be run right now
schedule()
assigned_splits = JobSplit.objects.filter(worker__isnull=False,
status=Job.QUEUED)
self.assertEqual(assigned_splits.count(), 0)
# simulate end job signal
split.end(Result(status=0))
self.assertEqual(split.job.status, Job.COMPLETED)
self.assertEqual(split.job.block.status, Block.CACHED)
self.assertEqual(split.job.block.experiment.status, Experiment.RUNNING)
# checks the number of statistics objects has increased by 1
self.assertEqual(HourlyStatistics.objects.count(), current_stats + 1)
self.check_stats_success(split)
# assert we have no database traces after the block is done
self.assertEqual(Job.objects.filter(block=split.job.block).count(), 0)
self.assertEqual(JobSplit.objects.filter(job=split.job).count(), 0)
self.assertEqual(Result.objects.filter(job__isnull=True).count(), 0)
self.assertEqual(worker.available_cores(), qsetup.CORES)
# since this job was successful, the next one should be ready to run
# schedules the last block of the experiment
assert xp.blocks.last().job.runnable_date is not None
schedule()
assigned_splits = JobSplit.objects.filter(worker__isnull=False)
self.assertEqual(assigned_splits.count(), 1)
split = assigned_splits.first()
self.assertEqual(split.job.block.experiment, xp)
self.assertEqual(split.job.block.name, 'analysis')
self.assertEqual(split.worker, worker)
self.assertEqual(worker.name, qsetup.HOSTNAME)
self.assertEqual(worker.available_cores(), qsetup.CORES)
# simulate job start on worker
split.start()
self.assertEqual(split.job.status, Job.PROCESSING)
self.assertEqual(split.job.block.status, Block.PROCESSING)
self.assertEqual(split.job.block.experiment.status, Experiment.RUNNING)
self.assertEqual(worker.available_cores(), qsetup.CORES-1)
# no job can be run right now
schedule()
assigned_splits = JobSplit.objects.filter(worker__isnull=False,
status=Job.QUEUED)
self.assertEqual(assigned_splits.count(), 0)
# simulate end job signal
split.end(Result(status=0))
# checks the number of statistics objects has increased by 1
self.assertEqual(HourlyStatistics.objects.count(), current_stats + 1)
self.assertEqual(split.job.status, Job.COMPLETED)
self.assertEqual(split.job.block.status, Block.CACHED)
self.assertEqual(split.job.block.experiment.status, Experiment.DONE)
self.check_stats_success(split)
# assert we have no database traces after the last block is done
self.assertEqual(Job.objects.count(), 0)
self.assertEqual(JobSplit.objects.count(), 0)
self.assertEqual(Result.objects.count(), 0)
self.assertEqual(worker.available_cores(), qsetup.CORES)
'''
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment