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

[backend] Implements successful experiment scheduling and execution testing

parent caf71f9f
No related branches found
No related tags found
1 merge request!194Scheduler
...@@ -43,11 +43,12 @@ from guardian.shortcuts import get_perms ...@@ -43,11 +43,12 @@ from guardian.shortcuts import get_perms
from ..common.testutils import BaseTestCase as APITestCase from ..common.testutils import BaseTestCase as APITestCase
from ..experiments.models import Experiment, Block from ..experiments.models import Experiment, Block
from ..algorithms.models import Algorithm from ..algorithms.models import Algorithm
from ..utils.management.commands import install
from ..statistics.models import HourlyStatistics
from .models import Queue, Worker, Slot, Environment, Job, JobSplit, Result from .models import Queue, Worker, Slot, Environment, Job, JobSplit, Result
from .utils import cleanup_cache, dump_backend, setup_backend from .utils import cleanup_cache, dump_backend, setup_backend
from .management.commands import qsetup from .management.commands import qsetup
from ..utils.management.commands import install
from .schedule import schedule from .schedule import schedule
...@@ -733,8 +734,21 @@ class BackendSetup(BaseBackendTestCase): ...@@ -733,8 +734,21 @@ class BackendSetup(BaseBackendTestCase):
class Scheduling(BaseBackendTestCase): class Scheduling(BaseBackendTestCase):
def check_stats_success(self, split):
assert abs(split.job.block.speed_up_real() - 1.0) < 0.1
assert abs(split.job.block.speed_up_maximal() - 1.0) < 0.1
assert split.job.block.linear_execution_time() > 0.0
assert split.job.block.queuing_time() > 0.0
assert split.job.block.stdout() is None
assert split.job.block.stderr() is None
assert split.job.block.error_report() is None
def test_success(self): def test_success(self):
current_stats = HourlyStatistics.objects.count()
fullname = 'user/user/single/1/single' fullname = 'user/user/single/1/single'
xp = Experiment.objects.get(name=fullname.split(os.sep)[-1]) xp = Experiment.objects.get(name=fullname.split(os.sep)[-1])
...@@ -743,6 +757,8 @@ class Scheduling(BaseBackendTestCase): ...@@ -743,6 +757,8 @@ class Scheduling(BaseBackendTestCase):
self.check_single(xp) self.check_single(xp)
# schedules the first runnable block # schedules the first runnable block
assert xp.blocks.first().job.runnable_date is not None
assert xp.blocks.last().job.runnable_date is None
schedule() schedule()
assigned_splits = JobSplit.objects.filter(worker__isnull=False) assigned_splits = JobSplit.objects.filter(worker__isnull=False)
...@@ -776,37 +792,63 @@ class Scheduling(BaseBackendTestCase): ...@@ -776,37 +792,63 @@ class Scheduling(BaseBackendTestCase):
self.assertEqual(split.job.block.status, Block.CACHED) self.assertEqual(split.job.block.status, Block.CACHED)
self.assertEqual(split.job.block.experiment.status, Experiment.RUNNING) self.assertEqual(split.job.block.experiment.status, Experiment.RUNNING)
''' # checks the number of statistics objects has increased by 1
nose.tools.eq_(block.result.stats.as_dict(), result.stats) self.assertEqual(HourlyStatistics.objects.count(), current_stats + 1)
self.check_stats_success(split)
self.assertEqual(worker.available_cores(), CORES) # 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 # since this job was successful, the next one should be ready to run
# schedules the last block of the experiment # schedules the last block of the experiment
jobs = s.jobs_to_run() assert xp.blocks.last().job.runnable_date is not None
self.assertEqual(len(jobs), 1) schedule()
job, worker = jobs.popitem(last=False)
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)
check_block_assignment(job, worker, xp, 'analysis', HOSTNAME, 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)
check_start_job(s, job, worker, xp) self.assertEqual(worker.available_cores(), qsetup.CORES-1)
self.assertEqual(worker.available_cores(), CORES-1)
# no job can be run right now # no job can be run right now
jobs = s.jobs_to_run() schedule()
self.assertEqual(len(jobs), 0) assigned_splits = JobSplit.objects.filter(worker__isnull=False,
status=Job.QUEUED)
self.assertEqual(assigned_splits.count(), 0)
# simulate end job signal # simulate end job signal
check_end_job_successfuly(s, job) split.end(Result(status=0))
# checks the number of statistics objects has increased by 1
self.assertEqual(HourlyStatistics.objects.count(), current_stats + 1)
# no more jobs scheduled self.assertEqual(split.job.status, Job.COMPLETED)
jobs = s.jobs_to_run() self.assertEqual(split.job.block.status, Block.CACHED)
self.assertEqual(len(jobs), 0) self.assertEqual(split.job.block.experiment.status, Experiment.DONE)
# experiment is now 'completed' self.check_stats_success(split)
self.assertEqual(xp.state, 'completed')
self.assertEqual(xp.dispatch, 'pending')
self.assertEqual(worker.available_cores(), CORES) # 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(Result.objects.filter(split__isnull=True).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