diff --git a/SAS/TMSS/backend/services/scheduling/test/t_dynamic_scheduling.py b/SAS/TMSS/backend/services/scheduling/test/t_dynamic_scheduling.py index ce383cd61f6f7e452e4bd97d20663d5af90e28cb..cb2e71b26db4cd13c957bfca7d476ee8b7b9c430 100755 --- a/SAS/TMSS/backend/services/scheduling/test/t_dynamic_scheduling.py +++ b/SAS/TMSS/backend/services/scheduling/test/t_dynamic_scheduling.py @@ -3385,6 +3385,45 @@ class TestDynamicScheduling(BaseDynamicSchedulingTestCase): self.assertEqual(su_blueprint.id, scored_scheduling_unit.scheduling_unit.id) + def test_bugfix_TMSS_2597_incorrect_unschedulable_reason_for_reserved_stations(self): + '''See https://support.astron.nl/jira/browse/TMSS-2597. + ''' + project = models.Project.objects.create(**Project_test_data(name=str(uuid.uuid4()), project_state=models.ProjectState.objects.get(value=models.ProjectState.Choices.ACTIVE.value))) + # create a short cycle, so the midterm scheduler is done quickly and the bug is triggered + cycle = models.Cycle.objects.create(**Cycle_test_data(name=str(uuid.uuid4()), + start=datetime.utcnow(), + stop=datetime.utcnow()+timedelta(days=1))) + project.cycles.set([cycle]) + project.save() + + scheduling_set = models.SchedulingSet.objects.create(**SchedulingSet_test_data(project=project)) + scheduling_unit_draft = self.create_simple_observation_scheduling_unit("scheduling unit for %s" % self._testMethodName, + scheduling_set=scheduling_set) + scheduling_unit_draft.scheduling_constraints_doc = {'scheduler': 'dynamic', + 'sky': {'min_elevation': {'target': 1.57}}} # unmeetable constraint + scheduling_unit_draft.save() + scheduling_unit_blueprint = create_scheduling_unit_blueprint_and_tasks_and_subtasks_from_scheduling_unit_draft(scheduling_unit_draft) + + # create a very short reservation, which is in the cycle window, but leaving plenty of room for the unit to be placed. + self.create_station_reservation(name="reservation for %s" % self._testMethodName, + stations=scheduling_unit_blueprint.main_observation_stations, + start_time=datetime.utcnow()+timedelta(hours=1), + stop_time =datetime.utcnow()+timedelta(hours=1, minutes=1)) + + # let the scheduler place the unit in the mid-term schedule. + # it should not find a spot (because of the high min_elevation) + self.scheduler.assign_start_stop_times_to_schedulable_scheduling_units(datetime.utcnow()) + + # check that it's unschedulable + scheduling_unit_blueprint.refresh_from_db() + self.assertEqual('unschedulable', scheduling_unit_blueprint.status.value) + + # check/reproduce the reported bug: + # the unschedulable_reason states that the unit is unschedulable due to station reservations, which is not what we want. + self.assertNotEqual("Stations are reserved", scheduling_unit_blueprint.unschedulable_reason) + + # we want the unschedulable_reason to report on the min_elevation + self.assertTrue("min_elevation" in scheduling_unit_blueprint.unschedulable_reason)