Skip to content

Commit b093522

Browse files
Fokkoashb
authored andcommitted
[AIRFLOW-2961] Refactor tests.BackfillJobTest.test_backfill_examples test (apache#3811)
Simplify this test since it takes up 15% of all the time. This is because every example dag, with some exclusions, are backfilled. This will put some pressure on the scheduler and everything. If the test just covers a couple of dags should be sufficient 254 seconds: [success] 15.03% tests.BackfillJobTest.test_backfill_examples: 254.9323s
1 parent 58d85a1 commit b093522

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

tests/test_jobs.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
configuration.load_test_config()
6464

65+
logger = logging.getLogger(__name__)
6566

6667
try:
6768
from unittest import mock
@@ -200,30 +201,33 @@ def test_backfill_multi_dates(self):
200201
def test_backfill_examples(self):
201202
"""
202203
Test backfilling example dags
203-
"""
204204
205-
# some DAGs really are just examples... but try to make them work!
206-
skip_dags = [
207-
'example_http_operator',
208-
'example_twitter_dag',
209-
'example_trigger_target_dag',
210-
'example_trigger_controller_dag', # tested above
211-
'test_utils', # sleeps forever
212-
'example_kubernetes_executor', # requires kubernetes cluster
213-
'example_kubernetes_operator' # requires kubernetes cluster
214-
]
205+
Try to backfill some of the example dags. Be carefull, not all dags are suitable
206+
for doing this. For example, a dag that sleeps forever, or does not have a
207+
schedule won't work here since you simply can't backfill them.
208+
"""
209+
include_dags = {
210+
'example_branch_operator',
211+
'example_bash_operator',
212+
'example_skip_dag',
213+
'latest_only'
214+
}
215215

216-
logger = logging.getLogger('BackfillJobTest.test_backfill_examples')
217216
dags = [
218217
dag for dag in self.dagbag.dags.values()
219-
if 'example_dags' in dag.full_filepath and dag.dag_id not in skip_dags
218+
if 'example_dags' in dag.full_filepath and dag.dag_id in include_dags
220219
]
221220

222221
for dag in dags:
223222
dag.clear(
224223
start_date=DEFAULT_DATE,
225224
end_date=DEFAULT_DATE)
226225

226+
# Make sure that we have the dags that we want to test available
227+
# in the example_dags folder, if this assertion fails, one of the
228+
# dags in the include_dags array isn't available anymore
229+
self.assertEqual(len(include_dags), len(dags))
230+
227231
for i, dag in enumerate(sorted(dags, key=lambda d: d.dag_id)):
228232
logger.info('*** Running example DAG #{}: {}'.format(i, dag.dag_id))
229233
job = BackfillJob(

0 commit comments

Comments
 (0)