ashb commented on a change in pull request #16401:
URL: https://github.com/apache/airflow/pull/16401#discussion_r659622069



##########
File path: tests/jobs/test_scheduler_job.py
##########
@@ -3457,37 +3445,43 @@ def 
test_do_schedule_max_active_runs_dag_timed_out(self):
         dagbag.bag_dag(dag=dag, root_dag=dag)
         dagbag.sync_to_db(session=session)
 
+        dag = SerializedDAG.from_dict(SerializedDAG.to_dict(dag))
+
         run1 = dag.create_dagrun(
             run_type=DagRunType.SCHEDULED,
             execution_date=DEFAULT_DATE,
-            state=State.RUNNING,
+            state=State.QUEUED,
             session=session,
         )
+        self.scheduler_job = SchedulerJob(subdir=os.devnull)
+        self.scheduler_job.executor = MockExecutor()
+        self.scheduler_job.processor_agent = 
mock.MagicMock(spec=DagFileProcessorAgent)
+
+        self.scheduler_job._do_scheduling(session)
+
         run1_ti = run1.get_task_instance(task1.task_id, session)
         run1_ti.state = State.RUNNING
 
-        sleep(1)
-
         run2 = dag.create_dagrun(
             run_type=DagRunType.SCHEDULED,
             execution_date=DEFAULT_DATE + timedelta(seconds=10),
-            state=State.RUNNING,
+            state=State.QUEUED,
             session=session,
         )
 
         dag.sync_to_db(session=session)
-
-        self.scheduler_job = SchedulerJob(subdir=os.devnull)
-        self.scheduler_job.executor = MockExecutor()
-        self.scheduler_job.processor_agent = 
mock.MagicMock(spec=DagFileProcessorAgent)
-
-        _ = self.scheduler_job._do_scheduling(session)
-
+        sleep(2)  # Should add this so it's timed out

Review comment:
       Rather than sleeping in the test, could set set "state=running, 
start_date = 2 seconds ago"?
   
   I.e. I want tests to be quick, and 2 second sleep isn't the end of the 
world, but if we can avoid that entirely then lets go for it. Every second 
counts almost.
   
   The other option would be to look at the time stepping feature of freezegun.




-- 
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]


Reply via email to