syedahsn commented on code in PR #38658:
URL: https://github.com/apache/airflow/pull/38658#discussion_r1602254073


##########
tests/providers/amazon/aws/sensors/test_emr_containers.py:
##########
@@ -84,3 +84,15 @@ def test_sensor_defer(self, mock_poke):
         assert isinstance(
             e.value.trigger, EmrContainerTrigger
         ), f"{e.value.trigger} is not a EmrContainerTrigger"
+
+    @mock.patch.object(
+        EmrContainerHook, "check_query_status", 
return_value=EmrContainerHook.INTERMEDIATE_STATES[0]
+    )
+    def test_sensor_defer_with_timeout(self, mock_check_query_status):
+        self.sensor.deferrable = True
+        self.sensor.max_polling_attempts = 1000
+
+        with pytest.raises(TaskDeferred):

Review Comment:
   The problem with this test is that `check_query_status` is never called, 
because the sensor calls `self.defer` which raises the `TaskDeferred` Exception 
(which you are checking for), which ends the execution (i.e. the trigger code 
is never run).
   
   What I would do here is just make sure that the Trigger is being called with 
the correct params (i.e. the supplied `max_polling_attempts`). The fact that 
the waiter calls the endpoint the correct number of times is technically the 
Trigger's responsibility. Because you are not overriding the `run` method of 
the `AwsBaseTrigger`, you should be fine with just ensuring that the correct 
parameters are being passed to the Trigger. The `run` method for the 
`AwsBaseTrigger` is tested in one 
[location](https://github.com/apache/airflow/blob/main/tests/providers/amazon/aws/triggers/test_base.py#L116).
 
   The same is true for the operator test above. 



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to