We have flaky scheduler test:


https://github.com/apache/airflow/pull/11659/checks?check_run_id=1279791496#step:6:527


_______________ TestSchedulerJob.test_scheduler_task_start_date ________________

self = <tests.jobs.test_scheduler_job.TestSchedulerJob testMethod=test_scheduler_task_start_date>

    def test_scheduler_task_start_date(self):
        """
        Test that the scheduler respects task start dates that are different from DAG start dates
        """
    
        dagbag = DagBag(dag_folder=os.path.join(settings.DAGS_FOLDER, "no_dags.py"), include_examples=False)
        dag_id = 'test_task_start_date_scheduling'
        dag = self.dagbag.get_dag(dag_id)
        dag.is_paused_upon_creation = False
        dagbag.bag_dag(dag=dag, root_dag=dag)
    
        # Deactivate other dags in this file so the scheduler doesn't waste time processing them
        other_dag = self.dagbag.get_dag('test_start_date_scheduling')
        other_dag.is_paused_upon_creation = True
        dagbag.bag_dag(dag=other_dag, root_dag=other_dag)
    
        dagbag.sync_to_db()
    
        scheduler = SchedulerJob(executor=self.null_exec,
                                 subdir=dag.fileloc,
                                 num_runs=2)
        scheduler.run()
    
        session = settings.Session()
        tiq = session.query(TaskInstance).filter(TaskInstance.dag_id == dag_id)
        ti1s = tiq.filter(TaskInstance.task_id == 'dummy1').all()
        ti2s = tiq.filter(TaskInstance.task_id == 'dummy2').all()
        self.assertEqual(len(ti1s), 0)
>       self.assertEqual(len(ti2s), 2)
E       AssertionError: 1 != 2
tests/jobs/test_scheduler_job.py
"""
        Test if a a dagrun will be set failed if timeout, even without max_active_runs
        """
        dag = DAG(dag_id='test_scheduler_fail_dagrun_timeout', start_date=DEFAULT_DATE)
        dag.dagrun_timeout = datetime.timedelta(seconds=60)
        DummyOperator(task_id='dummy', dag=dag, owner='airflow')
        scheduler = SchedulerJob(subdir=os.devnull)
        scheduler.dagbag.bag_dag(dag, root_dag=dag)
        scheduler.dagbag.sync_to_db()
        session = settings.Session()
        orm_dag = session.query(DagModel).get(dag.dag_id)
        assert orm_dag is not None
        dag = SerializedDAG.from_dict(SerializedDAG.to_dict(dag))
        scheduler = SchedulerJob(subdir=os.devnull)
        scheduler._create_dag_runs([orm_dag], session)
        drs = DagRun.find(dag_id=dag.dag_id, session=session)
        assert len(drs) == 1
        dr = drs[0]
        
        dr.start_date = timezone.utcnow() - datetime.timedelta(days=1)
        session.flush()
        
        scheduler.processor_agent = mock.Mock()
        scheduler.processor_agent.send_callback_to_execute = mock.Mock()
        scheduler._schedule_dag_run(dr, {}, session)
        session.flush()
        session.refresh(dr)