diff --git a/SAS/TMSS/backend/services/precalculations_service/test/t_precalculations_service.py b/SAS/TMSS/backend/services/precalculations_service/test/t_precalculations_service.py index 375695eb1ac9697c9bb57f3ead7d82a921160b39..1e077ff0149eb97dc13ddb0c5f5c150eeb8caec9 100644 --- a/SAS/TMSS/backend/services/precalculations_service/test/t_precalculations_service.py +++ b/SAS/TMSS/backend/services/precalculations_service/test/t_precalculations_service.py @@ -193,6 +193,34 @@ class TestPreCalculationService(unittest.TestCase): st_objects = StationTimeline.objects.filter(timestamp=datetime.date.today()) self.assertEqual(len(st_objects), nbr_stations) + def test_all_stations_calculated_with_two_jobs_started(self): + """ + Test if starting two jobs of (pre)calculation service results in no Exception, there are no + duplicate data stored (covered by the Constraints in the model) + It will test the scheduler with interval of 20 seconds, to make sure one interval after the start has been passed + """ + # Import here otherwise you get + # "django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings." + from lofar.sas.tmss.tmss.tmssapp.conversions import get_all_stations + from lofar.sas.tmss.tmss.tmssapp.models.calculations import StationTimeline + + nbr_stations = len(get_all_stations()) + # Initially there should be no data + self.assertEqual(len(StationTimeline.objects.all()), 0) + # Now we are going to create and start the calculation service with an interval of 20 sec + # nbr days to calculate ahead is 1 and nbr days before today 0 -> so it start with 'today' and after ~20 seconds + # 'tomorrow' etc.. + job = create_service_job_for_sunrise_and_sunset_calculations(20, 1, 0) + job2 = create_service_job_for_sunrise_and_sunset_calculations(20, 1, 0) + + job.start() + job2.start() + time.sleep(22) + job.stop() + job2.stop() + # Check what have been created should only be today and tomorrow + st_objects = StationTimeline.objects.all() + self.assertGreaterEqual(len(st_objects), 2 * nbr_stations) if __name__ == '__main__':