diff --git a/beat/web/backend/tests.py b/beat/web/backend/tests.py index 3fcf14e0dd7404f3708b49d3fc1c3d5031770f55..817fa1480db38607fa6ae22c2032890672289d27 100644 --- a/beat/web/backend/tests.py +++ b/beat/web/backend/tests.py @@ -43,11 +43,12 @@ from guardian.shortcuts import get_perms from ..common.testutils import BaseTestCase as APITestCase from ..experiments.models import Experiment, Block 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 .utils import cleanup_cache, dump_backend, setup_backend from .management.commands import qsetup -from ..utils.management.commands import install from .schedule import schedule @@ -733,8 +734,21 @@ class BackendSetup(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): + current_stats = HourlyStatistics.objects.count() + fullname = 'user/user/single/1/single' xp = Experiment.objects.get(name=fullname.split(os.sep)[-1]) @@ -743,6 +757,8 @@ class Scheduling(BaseBackendTestCase): self.check_single(xp) # 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() assigned_splits = JobSplit.objects.filter(worker__isnull=False) @@ -776,37 +792,63 @@ class Scheduling(BaseBackendTestCase): self.assertEqual(split.job.block.status, Block.CACHED) self.assertEqual(split.job.block.experiment.status, Experiment.RUNNING) - ''' - nose.tools.eq_(block.result.stats.as_dict(), result.stats) + # checks the number of statistics objects has increased by 1 + 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 # schedules the last block of the experiment - jobs = s.jobs_to_run() - self.assertEqual(len(jobs), 1) - job, worker = jobs.popitem(last=False) + 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) - 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(), CORES-1) + self.assertEqual(worker.available_cores(), qsetup.CORES-1) # no job can be run right now - jobs = s.jobs_to_run() - self.assertEqual(len(jobs), 0) + schedule() + assigned_splits = JobSplit.objects.filter(worker__isnull=False, + status=Job.QUEUED) + self.assertEqual(assigned_splits.count(), 0) # 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 - jobs = s.jobs_to_run() - self.assertEqual(len(jobs), 0) + self.assertEqual(split.job.status, Job.COMPLETED) + self.assertEqual(split.job.block.status, Block.CACHED) + self.assertEqual(split.job.block.experiment.status, Experiment.DONE) - # experiment is now 'completed' - self.assertEqual(xp.state, 'completed') - self.assertEqual(xp.dispatch, 'pending') + 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(Result.objects.filter(split__isnull=True).count(), 0) + + self.assertEqual(worker.available_cores(), qsetup.CORES)