XD-DENG commented on a change in pull request #4878: [AIRFLOW-4046] Added 
validations for poke_interval & timeout for Airflow Sensor
URL: https://github.com/apache/airflow/pull/4878#discussion_r263993430
 
 

 ##########
 File path: tests/sensors/test_base_sensor.py
 ##########
 @@ -464,3 +464,31 @@ def test_reschedule_with_test_mode(self):
                 self.assertEqual(len(task_reschedules), 0)
             if ti.task_id == DUMMY_OP:
                 self.assertEqual(ti.state, State.NONE)
+
+    def test_sensor_with_negetive_poke_interval(self):
+        negative_poke_interval = -10
+        positive_poke_interval = 10
+        with self.assertRaises(AirflowException):
+            sensor = self._make_sensor(
+                return_value=None,
+                poke_interval=negative_poke_interval,
+                timeout=25)
+        sensor = self._make_sensor(
+            return_value=None,
+            poke_interval=positive_poke_interval,
+            timeout=25)
+        self.assertEqual(sensor.poke_interval, positive_poke_interval)
+
+    def test_sensor_with_negetive_timeout(self):
+        negative_timeout = -25
+        positive_timeout = 25
+        with self.assertRaises(AirflowException):
+            sensor = self._make_sensor(
+                return_value=None,
+                poke_interval=10,
+                timeout=negative_timeout)
+        sensor = self._make_sensor(
+            return_value=None,
+            poke_interval=10,
+            timeout=positive_timeout)
+        self.assertEqual(sensor.timeout, positive_timeout)
 
 Review comment:
   The same comment as above. Running `self._make_sensor()` without exception 
is good enough to demonstrate the test. This line is a bit similar to running 
`instance = Class(attr=1)` then check if `instance.attr == 1` (it will return 
True for sure). (Please correct me if I missed anything)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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