mik-laj commented on a change in pull request #8051: [AIRFLOW-7045] Update SQL
query to delete RenderedTaskInstanceFields
URL: https://github.com/apache/airflow/pull/8051#discussion_r402015516
##########
File path: tests/models/test_renderedtifields.py
##########
@@ -139,29 +147,27 @@ def test_delete_old_records(self):
with dag:
task = BashOperator(task_id="test", bash_command="echo {{ ds }}")
- rtif_1 = RTIF(TI(task=task, execution_date=EXECUTION_DATE))
- rtif_2 = RTIF(TI(task=task, execution_date=EXECUTION_DATE +
timedelta(days=1)))
- rtif_3 = RTIF(TI(task=task, execution_date=EXECUTION_DATE +
timedelta(days=2)))
+ rtif_list = [
+ RTIF(TI(task=task, execution_date=EXECUTION_DATE +
timedelta(days=num)))
+ for num in range(rtif_num)
+ ]
- session.add(rtif_1)
- session.add(rtif_2)
- session.add(rtif_3)
+ session.add_all(rtif_list)
session.commit()
result = session.query(RTIF)\
.filter(RTIF.dag_id == dag.dag_id, RTIF.task_id ==
task.task_id).all()
- self.assertIn(rtif_1, result)
- self.assertIn(rtif_2, result)
- self.assertIn(rtif_3, result)
- self.assertEqual(3, len(result))
+ for rtif in rtif_list:
+ self.assertIn(rtif, result)
+
+ self.assertEqual(rtif_num, len(result))
- # Verify old records are deleted and only 1 record is kept
- RTIF.delete_old_records(task_id=task.task_id, dag_id=task.dag_id,
num_to_keep=1)
+ # Verify old records are deleted and only 'num_to_keep' records are
kept
+ RTIF.delete_old_records(task_id=task.task_id, dag_id=task.dag_id,
num_to_keep=num_to_keep)
Review comment:
Can you add assertions on the number of queries here? We are trying to
optimize these function to make them as efficient as possible. This should be
reflected in the tests.
----------------------------------------------------------------
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