ashb commented on a change in pull request #6654: AIRFLOW-6055: Option for 
exponential backoff in Sensors
URL: https://github.com/apache/airflow/pull/6654#discussion_r350167683
 
 

 ##########
 File path: tests/sensors/test_base_sensor.py
 ##########
 @@ -502,3 +502,28 @@ def test_sensor_with_invalid_timeout(self):
             return_value=None,
             poke_interval=10,
             timeout=positive_timeout)
+
+    def test_sensor_with_exponential_backoff_off(self):
+        sensor = self._make_sensor(
+            return_value=None,
+            poke_interval=5,
+            timeout=60,
+            exponential_backoff=False)
+
+        started_at = timezone.utcnow() - timedelta(seconds=10)
+        self.assertEqual(sensor._get_next_poke_interval(started_at, 1), 
sensor.poke_interval)
+        self.assertEqual(sensor._get_next_poke_interval(started_at, 2), 
sensor.poke_interval)
+
+    def test_sensor_with_exponential_backoff_on(self):
+        sensor = self._make_sensor(
+            return_value=None,
+            poke_interval=5,
+            timeout=60,
+            exponential_backoff=True)
+
+        started_at = timezone.utcnow() - timedelta(seconds=10)
+
+        interval1 = sensor._get_next_poke_interval(started_at, 1)
+        interval2 = sensor._get_next_poke_interval(started_at, 2)
+
+        self.assertTrue(interval2 >= sensor.poke_interval >= interval1)
 
 Review comment:
   In which case use mocking to make `timezone.utcnow` return a known constant 
value in the tests.
   
   Or if the "jitter" caused by this is small then 
   ```
   self.assertGreaterThanEqual(interval1, 5)
   self.assertLessThanEqual(interval1, 5.5)
   
   self.assertGreaterThanEqual(interval2, 6)
   self.assertLessThanEqual(interval2, 7)
   ```
   
   Those values are not right, but this is the sort of thing I'd like to see.

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