[
https://issues.apache.org/jira/browse/AIRFLOW-4358?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16824325#comment-16824325
]
ASF GitHub Bot commented on AIRFLOW-4358:
-----------------------------------------
ashb commented on pull request #5162: [AIRFLOW-4358] Speed up test_jobs by not
running tasks
URL: https://github.com/apache/airflow/pull/5162
Make sure you have checked _all_ steps below.
### Jira
- [x] https://issues.apache.org/jira/browse/AIRFLOW-4358
### Description
- [ ] We don't care about the behaviour of the tasks (we test those
elsewhere) - we just care that the task is "run" and yeilds a state, which we
can all do more directly.
On my laptop this takes the time for SchedulerJobTest from 133s to 35s,
and reduces the BackfillJobTests from >5mins to mere seconds!
I think this approach still tests the behaviour well enough
### Tests
- [x] Changed tests to check events that are run via executor, but it won't
run it
### Commits
- [x] My commits all reference Jira issues in their subject lines, and I
have squashed multiple commits if they address the same issue. In addition, my
commits follow the guidelines from "[How to write a good git commit
message](http://chris.beams.io/posts/git-commit/)":
1. Subject is separated from body by a blank line
1. Subject is limited to 50 characters (not including Jira issue reference)
1. Subject does not end with a period
1. Subject uses the imperative mood ("add", not "adding")
1. Body wraps at 72 characters
1. Body explains "what" and "why", not "how"
### Documentation
- [x] In case of new functionality, my PR adds documentation that describes
how to use it.
- All the public functions and the classes in the PR contain docstrings
that explain what it does
- If you implement backwards incompatible changes, please leave a note in
the [Updating.md](https://github.com/apache/airflow/blob/master/UPDATING.md) so
we can assign it to a appropriate release
### Code Quality
- [x] Passes `flake8`
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
> Decouple running actual tasks from test_jobs.py
> -----------------------------------------------
>
> Key: AIRFLOW-4358
> URL: https://issues.apache.org/jira/browse/AIRFLOW-4358
> Project: Apache Airflow
> Issue Type: Sub-task
> Components: tests
> Reporter: Ash Berlin-Taylor
> Assignee: Ash Berlin-Taylor
> Priority: Major
>
> In tests/test_jobs.py we have a lot of slow, fragile tests that test the
> behaviour of the "Jobs" - BackfillJob and SchedulerJob being the main two.
> Since we have tests that check that the executors will actually _run_ tasks
> we should "stub" out the executor and replace the executor in those tests
> with one that just records what tasks it was asked to run.
> This will hopefully speed up the tests and make them less fragile.
> A possible starting point:
> {code:title=test_jobs.diff}
> diff --git a/tests/test_jobs.py b/tests/test_jobs.py
> index e3ae8be1..aa919f90 100644
> --- a/tests/test_jobs.py
> +++ b/tests/test_jobs.py
> @@ -1384,6 +1384,14 @@ class LocalTaskJobTest(unittest.TestCase):
> class SchedulerJobTest(unittest.TestCase):
> + class NullExecutor(airflow.executors.base_executor.BaseExecutor):
> + def heartbeat(self, *args, **kwargs):
> + # This would normally pop tasks of the queue and run them.
> + pass
> +
> + def end():
> + pass
> +
> def setUp(self):
> clear_db_runs()
> clear_db_pools()
> @@ -1391,6 +1399,10 @@ class SchedulerJobTest(unittest.TestCase):
> clear_db_sla_miss()
> clear_db_errors()
> + # Speed up some tests by not running the tasks, just look at what we
> + # enqueue!
> + self.null_exec = self.NullExecutor()
> +
> @classmethod
> def setUpClass(cls):
> cls.dagbag = DagBag()
> @@ -1409,8 +1421,7 @@ class SchedulerJobTest(unittest.TestCase):
> def tearDownClass(cls):
> cls.patcher.stop()
> - @staticmethod
> - def run_single_scheduler_loop_with_no_dags(dags_folder):
> + def run_single_scheduler_loop_with_no_dags(self, dags_folder):
> """
> Utility function that runs a single scheduler loop without actually
> changing/scheduling any dags. This is useful to simulate the other
> side effects of
> @@ -1421,6 +1432,7 @@ class SchedulerJobTest(unittest.TestCase):
> :type directory: str
> """
> scheduler = SchedulerJob(
> + executor=self.null_exec,
> dag_id='this_dag_doesnt_exist', # We don't want to actually run
> anything
> num_runs=1,
> subdir=os.path.join(dags_folder))
> @@ -2483,6 +2495,7 @@ class SchedulerJobTest(unittest.TestCase):
> self.assertTrue(dag.start_date > datetime.datetime.utcnow())
> scheduler = SchedulerJob(dag_id,
> + executor=self.null_exec,
> subdir=os.path.join(TEST_DAG_FOLDER,
> 'test_scheduler_dags.py'),
> num_runs=1)
> scheduler.run()
> @@ -2491,6 +2504,7 @@ class SchedulerJobTest(unittest.TestCase):
> self.assertEqual(
> len(session.query(TI).filter(TI.dag_id == dag_id).all()), 0)
> session.commit()
> + self.assertEqual({}, self.null_exec.queued_tasks)
> # previously, running this backfill would kick off the Scheduler
> # because it would take the most recent run and start from there
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)