Skip to content

Commit

Permalink
Add a test for the error
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSpen210 committed Sep 28, 2024
1 parent 4892f66 commit e5f38f3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/trio/_tests/test_timeouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ async def sleep_3() -> None:
await check_takes_about(sleep_3, TARGET)


async def test_cannot_wake_sleep_forever() -> None:
# Test an error occurs if you manually wake sleep_forever().
task = trio.lowlevel.current_task()

async def wake_task() -> None:
await trio.lowlevel.checkpoint()
trio.lowlevel.reschedule(task, outcome.Value(None))

async with trio.open_nursery() as nursery:
nursery.start_soon(wake_task)
with pytest.raises(RuntimeError):
await trio.sleep_forever()


class TimeoutScope(Protocol):
def __call__(self, seconds: float, *, shield: bool) -> trio.CancelScope: ...

Expand Down
2 changes: 1 addition & 1 deletion src/trio/_timeouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def sleep_forever() -> NoReturn:
"""
await trio.lowlevel.wait_task_rescheduled(lambda _: trio.lowlevel.Abort.SUCCEEDED)
raise trio.TrioInternalError("Should never have been rescheduled!")
raise RuntimeError("Should never have been rescheduled!")


async def sleep_until(deadline: float) -> None:
Expand Down

0 comments on commit e5f38f3

Please sign in to comment.