phani8996 commented on a change in pull request #4111: [AIRFLOW-3266] Add AWS 
Athena Operator and hook
URL: https://github.com/apache/incubator-airflow/pull/4111#discussion_r230399221
 
 

 ##########
 File path: tests/contrib/operators/test_aws_athena_operator.py
 ##########
 @@ -48,42 +49,62 @@
 }
 
 
+class Iterator(object):
+
+    def __init__(self, tuple):
+        self.tuple = tuple
+
+    def __iter__(self):
+        return self
+
+    def __next__(self):
+        return self.tuple[randrange(len(self.tuple))]
+
+
 class TestAWSAthenaOperator(unittest.TestCase):
 
     def setUp(self):
         configuration.load_test_config()
 
         self.athena = AWSAthenaOperator(task_id='test_aws_athena_operator', 
query='SELECT * FROM TEST_TABLE',
                                         database='TEST_DATABASE', 
output_location='s3://test_s3_bucket/',
-                                        
client_request_token='eac427d0-1c6d-4dfb-96aa-2835d3ac6595')
+                                        
client_request_token='eac427d0-1c6d-4dfb-96aa-2835d3ac6595',
+                                        sleep_time=1)
 
     def test_init(self):
         self.assertEqual(self.athena.task_id, MOCK_DATA['task_id'])
         self.assertEqual(self.athena.query, MOCK_DATA['query'])
         self.assertEqual(self.athena.database, MOCK_DATA['database'])
         self.assertEqual(self.athena.aws_conn_id, 'aws_default')
         self.assertEqual(self.athena.client_request_token, 
MOCK_DATA['client_request_token'])
+        self.assertEqual(self.athena.sleep_time, 1)
+
+    @mock.patch.object(AWSAthenaHook, 'check_query_status', 
side_effect=Iterator(("RUNNING", "SUCCESS",)))
 
 Review comment:
   At first i thought of having `side_effect=("RUNNING", "SUCCESS",)`, but 
later i realised in a real query, task won't reach state `SUCCESS` in single 
sleep cycle. Randomly picking state sounds little odd but for our case, it will 
serve the process. We will get multiple `RUNNING` states and after few sleep 
cycles we will encounter `SUCCESS` state and `poll_query_results` will return 
the final state. To make this more understandable we can add bias to state 
`RUNNING` and make it look realistic. Returning `SUCCESS` in first check 
symbolises a fast query and `SUCCESS` after few checks symbolises long running 
queries which we cannot achieve with plain `side_effect=("RUNNING", "SUCCESS",)`

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to