|
37 | 37 | import pytest |
38 | 38 | import time_machine |
39 | 39 | from sqlalchemy import delete, func, select, update |
| 40 | +from sqlalchemy.dialects import mysql |
40 | 41 | from sqlalchemy.orm import joinedload |
41 | 42 |
|
42 | 43 | from airflow import settings |
@@ -1248,6 +1249,34 @@ def test_find_executable_task_instances_backfill(self, dag_maker): |
1248 | 1249 | assert {x.key for x in queued_tis} == {ti_non_backfill.key, ti_backfill.key} |
1249 | 1250 | session.rollback() |
1250 | 1251 |
|
| 1252 | + def test_find_executable_task_instances_mysql_hint_only_applies_to_inner_query(self, dag_maker, session): |
| 1253 | + dag_id = "SchedulerJobTest.test_find_executable_task_instances_mysql_hint_only_applies_to_inner_query" |
| 1254 | + task_id = "dummy" |
| 1255 | + with dag_maker(dag_id=dag_id, max_active_tasks=16): |
| 1256 | + task = EmptyOperator(task_id=task_id) |
| 1257 | + |
| 1258 | + scheduler_job = Job() |
| 1259 | + self.job_runner = SchedulerJobRunner(job=scheduler_job) |
| 1260 | + |
| 1261 | + dag_run = dag_maker.create_dagrun(run_type=DagRunType.SCHEDULED) |
| 1262 | + ti = dag_run.get_task_instance(task.task_id) |
| 1263 | + ti.state = State.SCHEDULED |
| 1264 | + session.merge(ti) |
| 1265 | + session.flush() |
| 1266 | + |
| 1267 | + captured_queries = [] |
| 1268 | + |
| 1269 | + def capture_locked_query(query, **kwargs): |
| 1270 | + captured_queries.append(query) |
| 1271 | + return query |
| 1272 | + |
| 1273 | + with mock.patch("airflow.jobs.scheduler_job_runner.with_row_locks", side_effect=capture_locked_query): |
| 1274 | + queued_tis = self.job_runner._executable_task_instances_to_queued(max_tis=32, session=session) |
| 1275 | + |
| 1276 | + assert {queued_ti.key for queued_ti in queued_tis} == {ti.key} |
| 1277 | + compiled_query = str(captured_queries[0].compile(dialect=mysql.dialect())) |
| 1278 | + assert compiled_query.count("USE INDEX (ti_state)") == 1 |
| 1279 | + |
1251 | 1280 | def test_find_executable_task_instances_pool(self, dag_maker): |
1252 | 1281 | dag_id = "SchedulerJobTest.test_find_executable_task_instances_pool" |
1253 | 1282 | task_id_1 = "dummy" |
|
0 commit comments