Skip to content

Commit

Permalink
fix test_run_process_internal_error, add test_bad_deliver_cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl committed Jan 11, 2024
1 parent 0547313 commit 22e4765
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/trio/_tests/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import pytest

import trio
from trio.testing import RaisesGroup
from trio.testing import Matcher, RaisesGroup

from .. import (
Event,
Expand Down Expand Up @@ -565,6 +565,27 @@ async def custom_deliver_cancel(proc: Process) -> None:
assert custom_deliver_cancel_called


def test_bad_deliver_cancel() -> None:
async def custom_deliver_cancel(proc: Process) -> None:
proc.terminate()
raise ValueError("foo")

async def do_stuff() -> None:
async with _core.open_nursery() as nursery:
nursery.start_soon(
partial(run_process, SLEEP(9999), deliver_cancel=custom_deliver_cancel)
)
await wait_all_tasks_blocked()
nursery.cancel_scope.cancel()

# double wrap from our nursery + the internal nursery
with RaisesGroup(RaisesGroup(Matcher(ValueError, "^foo$"))):
_core.run(do_stuff, strict_exception_groups=True)

with pytest.raises(ValueError, match="^foo$"):
_core.run(do_stuff, strict_exception_groups=False)

This comment has been minimized.

Copy link
@richardsheridan

richardsheridan Jan 11, 2024

Contributor

It's good to see this working, but it's not quite what I had described. I had set strict_exception_groups=False directly at the nursery in _subprocess._run_process, while the trio.run argument was True. I would be thrilled to be wrong about that, but I don't think it's an issue for this PR anymore.

This comment has been minimized.

Copy link
@jakkdl

jakkdl Jan 12, 2024

Author Member

even doing exactly that I'm unable to reproduce what you encountered. But if you can repro it do open an issue about it



async def test_warn_on_failed_cancel_terminate(monkeypatch: pytest.MonkeyPatch) -> None:
original_terminate = Process.terminate

Expand Down Expand Up @@ -630,9 +651,8 @@ async def very_broken_open(*args: object, **kwargs: object) -> str:
return "oops"

monkeypatch.setattr(trio._subprocess, "open_process", very_broken_open)
with pytest.raises(trio.TrioInternalError) as excinfo:
with RaisesGroup(AttributeError, AttributeError):
await run_process(EXIT_TRUE, capture_stdout=True)
assert RaisesGroup(AttributeError, AttributeError).matches(excinfo.value.__cause__)


# regression test for #2209
Expand Down

0 comments on commit 22e4765

Please sign in to comment.