test_doxygen_timeout.py

tests/test_doxygen_timeout.py

The doxygen timeout must be reachable while the child is still alive.

test_the_doxygen_timeout_fires_while_the_child_lives

None test_doxygen_timeout.test_the_doxygen_timeout_fires_while_the_child_lives(Path tmp_path, pytest.MonkeyPatch monkeypatch, bool close_fds)

The watchdog bounds a live child.

tests/test_doxygen_timeout.py:110

Show on the map →

Called by none

Calls _reap, _write_stub, run_doxygen

Checks

  • assert not thread.is_alive(), (f"run_doxygen was still running after {elapsed:.0f} s against a " f"{_INNER_TIMEOUT} s timeout — the bound is unreachable, which is the whole defect: " "the blocking read of the child's output sits upstream of the wait that carries it" )
  • assert isinstance(box.get("exc"), SystemExit), (f"expected the timeout path to exit; got {box.get('exc')!r}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002inferredtest_the_doxygen_timeout_fires_while_the_child_lives → run_doxygen → doxygen_supports_sqlite3
REQ-DDB-INDEX-001measuredtest_the_doxygen_timeout_fires_while_the_child_lives → run_doxygen
REQ-DDB-PIPE-003measuredtest_the_doxygen_timeout_fires_while_the_child_lives → run_doxygen → _build_doxyfile_content → extra_input_clears_exclude
REQ-DDB-PIPE-006measuredtest_the_doxygen_timeout_fires_while_the_child_lives → run_doxygen → clean_subprocess_env
Source · 43 lines
def test_the_doxygen_timeout_fires_while_the_child_lives(
    tmp_path: Path, monkeypatch: pytest.MonkeyPatch, close_fds: bool
) -> None:
    """`pipe-held-open` IS THE REGRESSION CASE and it failed before the watchdog: the call was
    still running at 20 s against a 3 s bound, because the blocking read sat upstream of the
    timeout. `fds-closed` passed even then, which is exactly why both are here — one of them
    alone would have called this fixed.

    `SystemExit` is the pass condition, not an accident: `run_doxygen` reports the timeout and
    exits non-zero, and asserting the EXIT distinguishes "the watchdog fired" from "the stub
    happened to end".

    @brief The watchdog bounds a live child.
    @version 1
    """
    stub_dir = _write_stub(tmp_path, close_fds)
    monkeypatch.setenv("PATH", f"{stub_dir}{os.pathsep}{os.environ['PATH']}")
    monkeypatch.setattr(doxygen, "_DOXYGEN_TIMEOUT", _INNER_TIMEOUT)

    box: dict[str, BaseException] = {}

    def _call() -> None:
        try:
            doxygen.run_doxygen(tmp_path / "Doxyfile", tmp_path, output_dir=tmp_path / "out")
        except BaseException as exc:  # SystemExit is the expected outcome
            box["exc"] = exc

    thread = threading.Thread(target=_call, daemon=True)
    started = time.monotonic()
    thread.start()
    try:
        thread.join(timeout=_OUTER_DEADLINE)
        elapsed = time.monotonic() - started
        assert not thread.is_alive(), (
            f"run_doxygen was still running after {elapsed:.0f} s against a "
            f"{_INNER_TIMEOUT} s timeout — the bound is unreachable, which is the whole defect: "
            "the blocking read of the child's output sits upstream of the wait that carries it"
        )
        assert isinstance(box.get("exc"), SystemExit), (
            f"expected the timeout path to exit; got {box.get('exc')!r}"
        )
    finally:
        _reap()

1 more lines, not shown

Activity · 13 steps
lines 125–125stub_dir = _write_stub(tmp_path, close_fds)lines 126–126monkeypatch.setenv("PATH", f"{stub_dir}{os.pathsep}{os.environ['PATH']}")lines 127–127monkeypatch.setattr(doxygen, "_DOXYGEN_TIMEOUT", _INNER_TIMEOUT)lines 129–129box: dict[str, BaseException] = {}lines 131–135def _call() -> None: try: doxygen.run_doxygen(tmp_path / "Doxyfile", tmp_path, output_dir=tmp_path / "out") except BaseException as exc: # SystemExit is the expected outcome box["exc"] = exclines 137–137thread = threading.Thread(target=_call, daemon=True)lines 138–138started = time.monotonic()lines 139–139thread.start()lines 140–140trylines 141–141thread.join(timeout=_OUTER_DEADLINE)lines 142–142elapsed = time.monotonic() - startedlines 143–147assert not thread.is_alive(), ( f"run_doxygen was still running after {elapsed:.0f} s against a " f"{_INNER_TIMEOUT} s timeout — the bound is unreachable, which is the whole defect: " "the blocking read of the child's output sits upstream of the wait that carries it" )lines 148–150assert isinstance(box.get("exc"), SystemExit), ( f"expected the timeout path to exit; got {box.get('exc')!r}" )