ashb commented on a change in pull request #4117: [AIRFLOW-3277] Correctly
observe DST transitions for cron
URL: https://github.com/apache/incubator-airflow/pull/4117#discussion_r229509804
##########
File path: tests/models.py
##########
@@ -580,6 +580,29 @@ def test_cycle(self):
with self.assertRaises(AirflowDagCycleException):
dag.test_cycle()
+ def test_following_previous_schedule(self):
+ """
+ Make sure DST transitions are properly observed
+ """
+ local_tz = pendulum.timezone('Europe/Zurich')
+ start = datetime(2018, 10, 28, 3, 00, tzinfo=local_tz)
+ utc = timezone.convert_to_utc(start)
+
+ dag = DAG('tz_dag', start_date=start, schedule_interval="'*/5 * * *
*'")
+ next = dag.following_schedule(utc)
+ next_local = local_tz.convert(next)
+
+ # should give 2018, 10, 28, 3, 5
+ self.assertEqual(next_local.hour, 3)
+ self.assertEqual(next_local.minute, 5)
+
+ prev = dag.previous_schedule(utc)
+ prev_local = local_tz.convert(prev)
+
+ # should give 2018, 10, 28, 1, 55
+ self.assertEqual(prev_local.hour, 1)
+ self.assertEqual(prev_local.minute, 55)
Review comment:
Tests that cover the 3am case:
```python
start = local_tz.convert(datetime.datetime(2018, 10, 27, 3, 0))
utc = timezone.convert_to_utc(start)
dag = DAG('tz_dag', start_date=start, schedule_interval='0 3 * * *')
next = dag.following_schedule(utc)
next_local = local_tz.convert(next)
self.assertEqual(str(next_local), "2018-10-28 03:00:00+01:00")
self.assertEqual(str(next), "2018-10-28 02:00:00+00:00")
prev = dag.previous_schedule(next)
prev_local = local_tz.convert(prev)
self.assertEqual(str(next_local), "2018-10-27 03:00:00+02:00") #
This fails.
self.assertEqual(str(next), "2018-10-27 01:00:00+00:00")
```
Buuut croniter's get_prev is flaky around DST transition :(
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services