jason810496 commented on code in PR #66222:
URL: https://github.com/apache/airflow/pull/66222#discussion_r3254563657


##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_pools.py:
##########
@@ -1133,6 +1134,50 @@ def test_update_mask_preserves_other_fields(self, 
test_client, session):
         assert updated_pool.description is None  # unchanged
         assert updated_pool.include_deferred is True  # unchanged
 
+    @pytest.mark.parametrize(
+        ("count_a", "count_b"),
+        [
+            (5, 10),  # testcase: pool count 5 compare with pool count 10
+            (5, 20),  # testcase: pool count 5 compare with pool count 20
+            (10, 20),  # testcase: pool count 10 compare with pool count 20
+        ],
+    )
+    def test_bulk_delete_query_count_is_independent_of_pool_count(
+        self, test_client, session, count_a, count_b
+    ):

Review Comment:
   ```suggestion
       @pytest.mark.parametrize(
           ("pool_count"),
           [5, 10, 20],
       )
       def test_bulk_delete_query_count_is_independent_of_pool_count(
           self, test_client, session, pool_count
       ):
   ```



##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_pools.py:
##########
@@ -1133,6 +1134,50 @@ def test_update_mask_preserves_other_fields(self, 
test_client, session):
         assert updated_pool.description is None  # unchanged
         assert updated_pool.include_deferred is True  # unchanged
 
+    @pytest.mark.parametrize(
+        ("count_a", "count_b"),
+        [
+            (5, 10),  # testcase: pool count 5 compare with pool count 10
+            (5, 20),  # testcase: pool count 5 compare with pool count 20
+            (10, 20),  # testcase: pool count 10 compare with pool count 20
+        ],
+    )
+    def test_bulk_delete_query_count_is_independent_of_pool_count(
+        self, test_client, session, count_a, count_b
+    ):
+        # Regression guard for the N+1 fix in 
BulkPoolService.handle_bulk_delete:
+        # the query count for a bulk delete must be the same regardless of how
+        # many pools are deleted. A regression that re-queries each pool inside
+        # the loop would add one SELECT per pool, so the larger run would issue
+        # strictly more queries than the smaller one.
+
+        def execute_and_count(num_pools: int) -> int:
+            pool_names = [f"perf_pool_{num_pools}_{i}" for i in 
range(num_pools)]
+            session.add_all(Pool(pool=name, slots=1, include_deferred=False) 
for name in pool_names)
+            session.commit()
+
+            request_body = {
+                "actions": [{"action": "delete", "entities": pool_names, 
"action_on_non_existence": "fail"}]
+            }
+
+            with count_queries() as result:
+                response = test_client.patch("/pools", json=request_body)
+
+            assert response.status_code == 200
+            assert sorted(response.json()["delete"]["success"]) == 
sorted(pool_names)
+            assert 
session.scalars(select(Pool).where(Pool.pool.in_(pool_names))).all() == []
+
+            return sum(result.values())
+
+        queries_a = execute_and_count(count_a)
+        queries_b = execute_and_count(count_b)

Review Comment:
   Then we just need to assert the count result equal to some constant. (We 
should get the exact same number anyway)



##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_pools.py:
##########
@@ -1133,6 +1134,50 @@ def test_update_mask_preserves_other_fields(self, 
test_client, session):
         assert updated_pool.description is None  # unchanged
         assert updated_pool.include_deferred is True  # unchanged
 
+    @pytest.mark.parametrize(
+        ("count_a", "count_b"),
+        [
+            (5, 10),  # testcase: pool count 5 compare with pool count 10
+            (5, 20),  # testcase: pool count 5 compare with pool count 20
+            (10, 20),  # testcase: pool count 10 compare with pool count 20
+        ],
+    )
+    def test_bulk_delete_query_count_is_independent_of_pool_count(
+        self, test_client, session, count_a, count_b
+    ):
+        # Regression guard for the N+1 fix in 
BulkPoolService.handle_bulk_delete:
+        # the query count for a bulk delete must be the same regardless of how
+        # many pools are deleted. A regression that re-queries each pool inside
+        # the loop would add one SELECT per pool, so the larger run would issue
+        # strictly more queries than the smaller one.
+
+        def execute_and_count(num_pools: int) -> int:

Review Comment:
   We don't need inner function.



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