107
107
ELASTIC_DAG_FILE = os .path .join (PERF_DAGS_FOLDER , "elastic_dag.py" )
108
108
109
109
TEST_DAG_FOLDER = os .environ ["AIRFLOW__CORE__DAGS_FOLDER" ]
110
+ EXAMPLE_DAGS_FOLDER = airflow .example_dags .__path__ [0 ]
110
111
DEFAULT_DATE = timezone .datetime (2016 , 1 , 1 )
111
112
DEFAULT_LOGICAL_DATE = timezone .coerce_datetime (DEFAULT_DATE )
112
113
TRY_NUMBER = 1
@@ -119,12 +120,6 @@ def disable_load_example():
119
120
yield
120
121
121
122
122
- @pytest .fixture
123
- def load_examples ():
124
- with conf_vars ({("core" , "load_examples" ): "True" }):
125
- yield
126
-
127
-
128
123
# Patch the MockExecutor into the dict of known executors in the Loader
129
124
@contextlib .contextmanager
130
125
def _loader_mock (mock_executors ):
@@ -3562,21 +3557,7 @@ def test_list_py_file_paths(self):
3562
3557
if file_name .endswith ((".py" , ".zip" )):
3563
3558
if file_name not in ignored_files :
3564
3559
expected_files .add (f"{ root } /{ file_name } " )
3565
- for file_path in list_py_file_paths (TEST_DAG_FOLDER , include_examples = False ):
3566
- detected_files .add (file_path )
3567
- assert detected_files == expected_files
3568
-
3569
- ignored_files = {
3570
- "helper.py" ,
3571
- }
3572
- example_dag_folder = airflow .example_dags .__path__ [0 ]
3573
- for root , _ , files in os .walk (example_dag_folder ):
3574
- for file_name in files :
3575
- if file_name .endswith ((".py" , ".zip" )):
3576
- if file_name not in ["__init__.py" ] and file_name not in ignored_files :
3577
- expected_files .add (os .path .join (root , file_name ))
3578
- detected_files .clear ()
3579
- for file_path in list_py_file_paths (TEST_DAG_FOLDER , include_examples = True ):
3560
+ for file_path in list_py_file_paths (TEST_DAG_FOLDER ):
3580
3561
detected_files .add (file_path )
3581
3562
assert detected_files == expected_files
3582
3563
@@ -5662,9 +5643,9 @@ def test_find_and_purge_zombies_nothing(self):
5662
5643
self .job_runner ._find_and_purge_zombies ()
5663
5644
executor .callback_sink .send .assert_not_called ()
5664
5645
5665
- def test_find_and_purge_zombies (self , load_examples , session , testing_dag_bundle ):
5666
- dagbag = DagBag ( TEST_DAG_FOLDER , read_dags_from_db = False )
5667
-
5646
+ def test_find_and_purge_zombies (self , session , testing_dag_bundle ):
5647
+ dagfile = os . path . join ( EXAMPLE_DAGS_FOLDER , "example_branch_operator.py" )
5648
+ dagbag = DagBag ( dagfile )
5668
5649
dag = dagbag .get_dag ("example_branch_operator" )
5669
5650
DAG .bulk_write_to_db ("testing" , None , [dag ])
5670
5651
data_interval = dag .infer_automated_data_interval (DEFAULT_LOGICAL_DATE )
@@ -5718,68 +5699,70 @@ def test_find_and_purge_zombies(self, load_examples, session, testing_dag_bundle
5718
5699
assert callback_request .ti .run_id == ti .run_id
5719
5700
assert callback_request .ti .map_index == ti .map_index
5720
5701
5721
- def test_zombie_message (self , load_examples , testing_dag_bundle ):
5702
+ def test_zombie_message (self , testing_dag_bundle , session ):
5722
5703
"""
5723
5704
Check that the zombie message comes out as expected
5724
5705
"""
5725
5706
5726
5707
dagbag = DagBag (TEST_DAG_FOLDER , read_dags_from_db = False )
5727
- with create_session () as session :
5728
- session .query (Job ).delete ()
5729
- dag = dagbag .get_dag ("example_branch_operator" )
5730
- DAG .bulk_write_to_db ("testing" , None , [dag ])
5731
-
5732
- data_interval = dag .infer_automated_data_interval (DEFAULT_LOGICAL_DATE )
5733
- triggered_by_kwargs = {"triggered_by" : DagRunTriggeredByType .TEST } if AIRFLOW_V_3_0_PLUS else {}
5734
- dag_run = dag .create_dagrun (
5735
- state = DagRunState .RUNNING ,
5736
- logical_date = DEFAULT_DATE ,
5737
- run_type = DagRunType .SCHEDULED ,
5738
- session = session ,
5739
- data_interval = data_interval ,
5740
- ** triggered_by_kwargs ,
5741
- )
5708
+ dagfile = os .path .join (EXAMPLE_DAGS_FOLDER , "example_branch_operator.py" )
5709
+ dagbag = DagBag (dagfile )
5710
+ dag = dagbag .get_dag ("example_branch_operator" )
5711
+ DAG .bulk_write_to_db ("testing" , None , [dag ])
5742
5712
5743
- scheduler_job = Job (executor = MockExecutor ())
5744
- self .job_runner = SchedulerJobRunner (job = scheduler_job , subdir = os .devnull )
5745
- self .job_runner .processor_agent = mock .MagicMock ()
5713
+ session .query (Job ).delete ()
5746
5714
5747
- # We will provision 2 tasks so we can check we only find zombies from this scheduler
5748
- tasks_to_setup = ["branching" , "run_this_first" ]
5715
+ data_interval = dag .infer_automated_data_interval (DEFAULT_LOGICAL_DATE )
5716
+ triggered_by_kwargs = {"triggered_by" : DagRunTriggeredByType .TEST } if AIRFLOW_V_3_0_PLUS else {}
5717
+ dag_run = dag .create_dagrun (
5718
+ state = DagRunState .RUNNING ,
5719
+ logical_date = DEFAULT_DATE ,
5720
+ run_type = DagRunType .SCHEDULED ,
5721
+ session = session ,
5722
+ data_interval = data_interval ,
5723
+ ** triggered_by_kwargs ,
5724
+ )
5749
5725
5750
- for task_id in tasks_to_setup :
5751
- task = dag .get_task (task_id = task_id )
5752
- ti = TaskInstance (task , run_id = dag_run .run_id , state = State .RUNNING )
5753
- ti .queued_by_job_id = 999
5726
+ scheduler_job = Job (executor = MockExecutor ())
5727
+ self .job_runner = SchedulerJobRunner (job = scheduler_job , subdir = os .devnull )
5728
+ self .job_runner .processor_agent = mock .MagicMock ()
5754
5729
5755
- session . add ( ti )
5756
- session . flush ()
5730
+ # We will provision 2 tasks so we can check we only find zombies from this scheduler
5731
+ tasks_to_setup = [ "branching" , "run_this_first" ]
5757
5732
5758
- assert task .task_id == "run_this_first" # Make sure we have the task/ti we expect
5733
+ for task_id in tasks_to_setup :
5734
+ task = dag .get_task (task_id = task_id )
5735
+ ti = TaskInstance (task , run_id = dag_run .run_id , state = State .RUNNING )
5736
+ ti .queued_by_job_id = 999
5759
5737
5760
- ti . queued_by_job_id = scheduler_job . id
5738
+ session . add ( ti )
5761
5739
session .flush ()
5762
5740
5763
- zombie_message = self .job_runner ._generate_zombie_message_details (ti )
5764
- assert zombie_message == {
5765
- "DAG Id" : "example_branch_operator" ,
5766
- "Task Id" : "run_this_first" ,
5767
- "Run Id" : "scheduled__2016-01-01T00:00:00+00:00" ,
5768
- }
5769
-
5770
- ti .hostname = "10.10.10.10"
5771
- ti .map_index = 2
5772
- ti .external_executor_id = "abcdefg"
5773
-
5774
- zombie_message = self .job_runner ._generate_zombie_message_details (ti )
5775
- assert zombie_message == {
5776
- "DAG Id" : "example_branch_operator" ,
5777
- "Task Id" : "run_this_first" ,
5778
- "Run Id" : "scheduled__2016-01-01T00:00:00+00:00" ,
5779
- "Hostname" : "10.10.10.10" ,
5780
- "Map Index" : 2 ,
5781
- "External Executor Id" : "abcdefg" ,
5782
- }
5741
+ assert task .task_id == "run_this_first" # Make sure we have the task/ti we expect
5742
+
5743
+ ti .queued_by_job_id = scheduler_job .id
5744
+ session .flush ()
5745
+
5746
+ zombie_message = self .job_runner ._generate_zombie_message_details (ti )
5747
+ assert zombie_message == {
5748
+ "DAG Id" : "example_branch_operator" ,
5749
+ "Task Id" : "run_this_first" ,
5750
+ "Run Id" : "scheduled__2016-01-01T00:00:00+00:00" ,
5751
+ }
5752
+
5753
+ ti .hostname = "10.10.10.10"
5754
+ ti .map_index = 2
5755
+ ti .external_executor_id = "abcdefg"
5756
+
5757
+ zombie_message = self .job_runner ._generate_zombie_message_details (ti )
5758
+ assert zombie_message == {
5759
+ "DAG Id" : "example_branch_operator" ,
5760
+ "Task Id" : "run_this_first" ,
5761
+ "Run Id" : "scheduled__2016-01-01T00:00:00+00:00" ,
5762
+ "Hostname" : "10.10.10.10" ,
5763
+ "Map Index" : 2 ,
5764
+ "External Executor Id" : "abcdefg" ,
5765
+ }
5783
5766
5784
5767
def test_find_zombies_handle_failure_callbacks_are_correctly_passed_to_dag_processor (
5785
5768
self , testing_dag_bundle
0 commit comments