Taragolis commented on code in PR #38893:
URL: https://github.com/apache/airflow/pull/38893#discussion_r1559426316
##########
tests/jobs/test_local_task_job.py:
##########
@@ -886,53 +907,53 @@ def test_process_sigterm_works_with_retries(
execution_date = DEFAULT_DATE
run_id = f"test-{execution_date.date().isoformat()}"
- # Run LocalTaskJob in separate process
- proc = mp_context.Process(
- target=self._sigterm_local_task_runner,
- args=(dag_id, task_id, run_id, execution_date, task_started,
retry_callback_called),
- name="LocalTaskJob-TestProcess",
- daemon=daemon,
- )
- proc.start()
-
- try:
- with timeout(wait_timeout, "Timeout during waiting start
LocalTaskJob"):
- while task_started.value == 0:
- time.sleep(0.2)
- os.kill(proc.pid, signal.SIGTERM)
-
- with timeout(wait_timeout, "Timeout during waiting callback"):
- while retry_callback_called.value == 0:
- time.sleep(0.2)
- finally:
- proc.kill()
-
- assert retry_callback_called.value == 1
- # Internally callback finished before TaskInstance commit changes in
DB (as of Jan 2022).
- # So we can't easily check TaskInstance.state without any race
conditions drawbacks,
- # and fact that process with LocalTaskJob could be already killed.
- # We could add state validation (`UP_FOR_RETRY`) if callback mechanism
changed.
-
- pytest_capture = request.config.option.capture
- if pytest_capture == "no":
- # Since we run `LocalTaskJob` in the separate process we can grab
ut easily by `caplog`.
- # However, we could grab it from stdout/stderr but only if `-s`
flag set, see:
- # https://github.com/pytest-dev/pytest/issues/5997
- captured = capfd.readouterr()
+ with tempfile.NamedTemporaryFile() as tmpfile:
Review Comment:
`NamedTemporaryFile` would be remove temporary file in the end of the
context, ad it also add additional "ladder level" which reduce readability, and
this test not straight forward and use some hacks, so better avoid addition
indention level.
In the other side `tmp_path` returns unique
[`pathlib.Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)
directory with lifecycle depends on retention policy, for now we have retention
policy remove for success run and keep for 2 sequential in case of failure.
--
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]