potiuk commented on code in PR #30376:
URL: https://github.com/apache/airflow/pull/30376#discussion_r1162833770


##########
tests/cli/commands/test_jobs_command.py:
##########
@@ -75,52 +78,64 @@ def 
test_should_report_success_for_one_working_scheduler_with_hostname(self):
 
     def test_should_report_success_for_ha_schedulers(self):
         scheduler_jobs = []
+        job_runners = []
         with create_session() as session:
             for _ in range(3):
-                scheduler_job = Job(job_runner=SchedulerJobRunner())
+                scheduler_job = Job()
+                job_runner = SchedulerJobRunner(job=scheduler_job)
                 scheduler_job.state = State.RUNNING
                 session.add(scheduler_job)
                 scheduler_jobs.append(scheduler_job)
+                job_runners.append(job_runner)
             session.commit()
-            scheduler_job.heartbeat()
-
-        with contextlib.redirect_stdout(io.StringIO()) as temp_stdout:
-            jobs_command.check(
-                self.parser.parse_args(
-                    ["jobs", "check", "--job-type", "SchedulerJob", "--limit", 
"100", "--allow-multiple"]
+            
scheduler_job.heartbeat(heartbeat_callback=job_runner.heartbeat_callback)
+        try:
+            with contextlib.redirect_stdout(io.StringIO()) as temp_stdout:
+                jobs_command.check(
+                    self.parser.parse_args(
+                        ["jobs", "check", "--job-type", "SchedulerJob", 
"--limit", "100", "--allow-multiple"]
+                    )
                 )
-            )
-        assert "Found 3 alive jobs." in temp_stdout.getvalue()
-        for scheduler_job in scheduler_jobs:
-            if scheduler_job.job_runner.processor_agent:
-                scheduler_job.job_runner.processor_agent.end()
+            assert "Found 3 alive jobs." in temp_stdout.getvalue()
+        finally:

Review Comment:
   Yeah. The problem is that if we don't and we have an error raised here, the 
jobs will hang around and produce side-effects for other tests (and other tests 
get flaky).. Adding try/finally here helps in cas



##########
tests/cli/commands/test_jobs_command.py:
##########
@@ -75,52 +78,64 @@ def 
test_should_report_success_for_one_working_scheduler_with_hostname(self):
 
     def test_should_report_success_for_ha_schedulers(self):
         scheduler_jobs = []
+        job_runners = []
         with create_session() as session:
             for _ in range(3):
-                scheduler_job = Job(job_runner=SchedulerJobRunner())
+                scheduler_job = Job()
+                job_runner = SchedulerJobRunner(job=scheduler_job)
                 scheduler_job.state = State.RUNNING
                 session.add(scheduler_job)
                 scheduler_jobs.append(scheduler_job)
+                job_runners.append(job_runner)
             session.commit()
-            scheduler_job.heartbeat()
-
-        with contextlib.redirect_stdout(io.StringIO()) as temp_stdout:
-            jobs_command.check(
-                self.parser.parse_args(
-                    ["jobs", "check", "--job-type", "SchedulerJob", "--limit", 
"100", "--allow-multiple"]
+            
scheduler_job.heartbeat(heartbeat_callback=job_runner.heartbeat_callback)
+        try:
+            with contextlib.redirect_stdout(io.StringIO()) as temp_stdout:
+                jobs_command.check(
+                    self.parser.parse_args(
+                        ["jobs", "check", "--job-type", "SchedulerJob", 
"--limit", "100", "--allow-multiple"]
+                    )
                 )
-            )
-        assert "Found 3 alive jobs." in temp_stdout.getvalue()
-        for scheduler_job in scheduler_jobs:
-            if scheduler_job.job_runner.processor_agent:
-                scheduler_job.job_runner.processor_agent.end()
+            assert "Found 3 alive jobs." in temp_stdout.getvalue()
+        finally:

Review Comment:
   Yeah. The problem is that if we don't and we have an error raised here, the 
jobs will hang around and produce side-effects for other tests (and other tests 
get flaky).. Adding try/finally here helps in this case.



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