You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/08/02 07:57:00 UTC

[GitHub] [airflow] uranusjr commented on a change in pull request #17209: ECSOperator returns last logs when ECS task fails

uranusjr commented on a change in pull request #17209:
URL: https://github.com/apache/airflow/pull/17209#discussion_r680742982



##########
File path: tests/providers/amazon/aws/operators/test_ecs.py
##########
@@ -228,11 +247,24 @@ def test_check_success_tasks_raises(self):
         with pytest.raises(Exception) as ctx:
             self.ecs._check_success_task()
 
-        # Ordering of str(dict) is not guaranteed.
-        assert "This task is not in success state " in str(ctx.value)
-        assert "'name': 'foo'" in str(ctx.value)
-        assert "'lastStatus': 'STOPPED'" in str(ctx.value)
-        assert "'exitCode': 1" in str(ctx.value)
+        assert str(ctx.value) == (
+            f"This task is not in success state - last 10 logs from Cloudwatch:\n1\n2\n3\n4\n5"

Review comment:
       ```suggestion
               "This task is not in success state - last 10 logs from Cloudwatch:\n1\n2\n3\n4\n5"
   ```

##########
File path: tests/providers/amazon/aws/operators/test_ecs.py
##########
@@ -228,11 +247,24 @@ def test_check_success_tasks_raises(self):
         with pytest.raises(Exception) as ctx:
             self.ecs._check_success_task()
 
-        # Ordering of str(dict) is not guaranteed.
-        assert "This task is not in success state " in str(ctx.value)
-        assert "'name': 'foo'" in str(ctx.value)
-        assert "'lastStatus': 'STOPPED'" in str(ctx.value)
-        assert "'exitCode': 1" in str(ctx.value)
+        assert str(ctx.value) == (
+            f"This task is not in success state - last 10 logs from Cloudwatch:\n1\n2\n3\n4\n5"
+        )
+        client_mock.describe_tasks.assert_called_once_with(cluster='c', tasks=['arn'])
+
+    @mock.patch.object(ECSOperator, '_last_log_messages', return_value=[])
+    def test_check_success_tasks_raises_cloudwatch_logs_empty(self, mock_last_log_messages):
+        client_mock = mock.Mock()
+        self.ecs.arn = 'arn'
+        self.ecs.client = client_mock
+
+        client_mock.describe_tasks.return_value = {
+            'tasks': [{'containers': [{'name': 'foo', 'lastStatus': 'STOPPED', 'exitCode': 1}]}]
+        }
+        with pytest.raises(Exception) as ctx:
+            self.ecs._check_success_task()
+
+        assert str(ctx.value) == (f"This task is not in success state - last 10 logs from Cloudwatch:\n")

Review comment:
       ```suggestion
           assert str(ctx.value) == "This task is not in success state - last 10 logs from Cloudwatch:\n"
   ```




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org