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_r229494185
 
 

 ##########
 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:
   I'm not quite sure we're constructing the DTs right here. (cos 2am local is 
ambigious time). This makes sure that the pre-condition time is correct:
   
   ```
           local_tz = pendulum.timezone('Europe/Zurich')
           start = local_tz.convert(datetime.datetime(2018, 10, 28, 2, 55), 
dst_rule=pendulum.PRE_TRANSITION)
           self.assertEqual(str(start), "2018-10-28 02:55:00+02:00", 
"Pre-condition: start date is in DST")
   
           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)
   
           self.assertEqual(str(next), "2018-10-28 01:00:00+00:00")
           self.assertEqual(str(next_local), "2018-10-28 02:00:00+01:00")
   
           prev = dag.previous_schedule(utc)
           prev_local = local_tz.convert(prev)
   
           self.assertEqual(str(prev_local), "2018-10-28 02:50:00+02:00")
   
           prev = dag.previous_schedule(next)
           prev_local = local_tz.convert(prev)
   
           self.assertEqual(str(prev_local), "2018-10-28 02:55:00+02:00")
           self.assertEqual(prev, utc)
   ```

----------------------------------------------------------------
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

Reply via email to