jason810496 commented on code in PR #60216:
URL: https://github.com/apache/airflow/pull/60216#discussion_r2802854746
##########
airflow-core/tests/unit/models/test_backfill.py:
##########
@@ -363,16 +369,73 @@ def test_active_dag_run(dag_maker, session):
dag_run_conf={"this": "param"},
)
assert b1 is not None
- with pytest.raises(AlreadyRunningBackfill, match="Another backfill is
running for dag"):
- _create_backfill(
- dag_id=dag.dag_id,
- from_date=pendulum.parse("2021-02-01"),
- to_date=pendulum.parse("2021-02-05"),
- max_active_runs=10,
- reverse=False,
- triggering_user_name="pytest",
- dag_run_conf={"this": "param"},
- )
+
+ # Create overlapping backfill (2021-01-03 to 2021-01-07), should succeed
+ # All 5 dates get a BackfillDagRun. 01-03..01-05 are IN_FLIGHT, 01-06 and
01-07 get DagRuns
+ b2 = _create_backfill(
+ dag_id=dag.dag_id,
+ from_date=pendulum.parse("2021-01-03"),
+ to_date=pendulum.parse("2021-01-07"),
+ max_active_runs=10,
+ reverse=False,
+ triggering_user_name="pytest",
+ dag_run_conf={"this": "param"},
+ )
+ assert b2 is not None
+ assert b1.id != b2.id
+
+ b2_runs = list(
+ session.scalars(
+ select(BackfillDagRun)
+ .where(BackfillDagRun.backfill_id == b2.id)
+ .order_by(BackfillDagRun.logical_date)
+ ).all()
+ )
+ assert len(b2_runs) == 5
+
+ in_flight_dates = {
+ bdr.logical_date.date().isoformat()
+ for bdr in b2_runs
+ if bdr.exception_reason == BackfillDagRunExceptionReason.IN_FLIGHT
+ }
+ created_dates = {bdr.logical_date.date().isoformat() for bdr in b2_runs if
bdr.dag_run_id is not None}
+
+ assert in_flight_dates == {"2021-01-03", "2021-01-04", "2021-01-05"}
+ assert created_dates == {"2021-01-06", "2021-01-07"}
+
+
+def test_non_overlapping_backfills_can_be_created(dag_maker, session):
+ """
+ Verify that two non-overlapping backfills can be created for the same Dag.
+ """
+ with dag_maker(schedule="@daily") as dag:
+ PythonOperator(task_id="hi", python_callable=print)
+ session.commit()
+
+ # Create first backfill
+ b1 = _create_backfill(
+ dag_id=dag.dag_id,
+ from_date=pendulum.parse("2021-01-01"),
+ to_date=pendulum.parse("2021-01-05"),
+ max_active_runs=10,
+ reverse=False,
+ triggering_user_name="pytest",
+ dag_run_conf={},
+ )
+ assert b1 is not None
+
+ # Create second non-overlapping backfill - should succeed
+ b2 = _create_backfill(
+ dag_id=dag.dag_id,
+ from_date=pendulum.parse("2021-01-10"), # No overlap with first
backfill
+ to_date=pendulum.parse("2021-01-15"),
+ max_active_runs=10,
+ reverse=False,
+ triggering_user_name="pytest",
+ dag_run_conf={},
+ )
+ assert b2 is not None
+ assert b1.id != b2.id
Review Comment:
Could we please verify the expected `BackfillDagRun` for
`test_non_overlapping_backfills_can_be_created` test case? Thanks!
--
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]