jedcunningham commented on a change in pull request #17797: URL: https://github.com/apache/airflow/pull/17797#discussion_r695890136
########## File path: tests/task/task_runner/test_standard_task_runner.py ########## @@ -181,40 +179,40 @@ def test_on_kill(self): except OSError: pass - dagbag = models.DagBag( + dagbag = DagBag( dag_folder=TEST_DAG_FOLDER, include_examples=False, ) dag = dagbag.dags.get('test_on_kill') task = dag.get_task('task1') - session = settings.Session() + with create_session() as session: + dag.clear() + dag.create_dagrun( + run_id="test", + state=State.RUNNING, + execution_date=DEFAULT_DATE, + start_date=DEFAULT_DATE, + session=session, + ) + ti = TaskInstance(task=task, execution_date=DEFAULT_DATE) + job1 = LocalTaskJob(task_instance=ti, ignore_ti_state=True) - dag.clear() - dag.create_dagrun( - run_id="test", - state=State.RUNNING, - execution_date=DEFAULT_DATE, - start_date=DEFAULT_DATE, - session=session, - ) - ti = TI(task=task, execution_date=DEFAULT_DATE) - job1 = LocalTaskJob(task_instance=ti, ignore_ti_state=True) - session.commit() + runner = StandardTaskRunner(job1) + runner.start() - runner = StandardTaskRunner(job1) - runner.start() + # give the task some time to startup + time.sleep(3) - # give the task some time to startup - time.sleep(3) + pgid = os.getpgid(runner.process.pid) + assert pgid > 0 + assert pgid != os.getpgid(0), "Task should be in a different process group to us" - pgid = os.getpgid(runner.process.pid) - assert pgid > 0 - assert pgid != os.getpgid(0), "Task should be in a different process group to us" + processes = list(self._procs_in_pgroup(pgid)) - processes = list(self._procs_in_pgroup(pgid)) + runner.terminate() - runner.terminate() + session.close() # explicitly close as `create_session`s commit will blow up otherwise Review comment: `rollback` doesn't work, `terminate` seemingly already kills the transaction. -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org