diff --git a/SAS/TMSS/services/scheduling/test/t_dynamic_scheduling.py b/SAS/TMSS/services/scheduling/test/t_dynamic_scheduling.py index 4239f1cc380b998dd4d0e4975d05ce3865afda76..d981c692979580b1400ebdd83b6885cab9ab2a98 100755 --- a/SAS/TMSS/services/scheduling/test/t_dynamic_scheduling.py +++ b/SAS/TMSS/services/scheduling/test/t_dynamic_scheduling.py @@ -51,11 +51,10 @@ class TestDynamicScheduling(unittest.TestCase): # import here, and not at top of module, because DEFAULT_BUSNAME needs to be set before importing from lofar.sas.tmss.test.test_utils import TMSSTestEnvironment - from lofar.sas.tmss.test.tmss_test_data_rest import TMSSRESTTestDataCreator cls.tmss_test_env = TMSSTestEnvironment(exchange=cls.tmp_exchange.address, populate_schemas=True, populate_test_data=False, - start_pg_listener=True, start_subtask_scheduler=False, + start_postgres_listener=True, start_subtask_scheduler=False, start_ra_test_environment=True, enable_viewflow=False, start_dynamic_scheduler=False) # do not start the dynamic scheduler in the testenv, because it is the object-under-test. cls.tmss_test_env.start() @@ -72,7 +71,6 @@ class TestDynamicScheduling(unittest.TestCase): obs_duration:int=60, constraints=None): from lofar.sas.tmss.tmss.tmssapp import models - from lofar.sas.tmss.tmss.tmssapp.tasks import create_task_blueprints_and_subtasks_from_scheduling_unit_draft constraints_template = models.SchedulingConstraintsTemplate.objects.get(name="constraints") constraints = add_defaults_to_json_object_for_schema(constraints or {}, constraints_template.schema) @@ -91,11 +89,11 @@ class TestDynamicScheduling(unittest.TestCase): scheduling_constraints_template=constraints_template) - def test_01(self): - from lofar.sas.tmss.tmss.tmssapp.tasks import create_task_blueprints_and_subtasks_from_scheduling_unit_draft, schedule_independent_subtasks_in_scheduling_unit_blueprint + def test_two_simple_observations_no_constraints_different_project_priority(self): + from lofar.sas.tmss.tmss.tmssapp.tasks import create_task_blueprints_and_subtasks_from_scheduling_unit_draft from lofar.sas.tmss.tmss.tmssapp import models from lofar.sas.tmss.test.tmss_test_data_django_models import SchedulingSet_test_data, Project_test_data - from lofar.sas.tmss.services.dynamic_scheduling import schedule_next_scheduling_unit + from lofar.sas.tmss.services.dynamic_scheduling import schedule_next_scheduling_unit, assign_start_stop_times_to_schedulable_scheduling_units project1 = models.Project.objects.create(**Project_test_data("dynamic scheduling test project %s"% (uuid.uuid4(),), priority_rank=1)) project2 = models.Project.objects.create(**Project_test_data("dynamic scheduling test project %s"% (uuid.uuid4(),), priority_rank=2)) @@ -117,14 +115,23 @@ class TestDynamicScheduling(unittest.TestCase): self.assertEqual(scheduling_unit_blueprint2.id, scheduled_scheduling_unit.id) # check the results - upcoming_scheduled_subtasks = models.Subtask.objects.filter(state__value='scheduled', - start_time__gt=datetime.utcnow()) + # we expect the sub2 to be scheduled, and sub1 to have a starttime after sub2 + scheduling_unit_blueprint1.refresh_from_db() + scheduling_unit_blueprint2.refresh_from_db() + self.assertEqual(scheduling_unit_blueprint1.status, 'schedulable') + self.assertEqual(scheduling_unit_blueprint2.status, 'scheduled') - # we expect the 1st and 2nd Calibrator and the Target observation subtasks of scheduling_unit_blueprint2 to be scheduled + # check the scheduled subtask + upcoming_scheduled_subtasks = models.Subtask.objects.filter(state__value='scheduled', + start_time__gt=datetime.utcnow(), + task_blueprint__scheduling_unit_blueprint__in=(scheduling_unit_blueprint1, scheduling_unit_blueprint2)).all() self.assertEqual(1, upcoming_scheduled_subtasks.count()) - for subtask in upcoming_scheduled_subtasks: - self.assertTrue(subtask in models.Subtask.objects.filter(task_blueprint__scheduling_unit_blueprint=scheduled_scheduling_unit).all()) - self.assertEqual(subtask.specifications_template.type.value, models.SubtaskType.Choices.OBSERVATION.value) + self.assertEqual(scheduling_unit_blueprint2.id, upcoming_scheduled_subtasks[0].task_blueprint.scheduling_unit_blueprint.id) + + # create the "mid-term schedule" (consisting the the one remaining sub1) + assign_start_stop_times_to_schedulable_scheduling_units() + self.assertGreater(scheduling_unit_blueprint1.start_time, scheduling_unit_blueprint2.start_time) + logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)