Skip to content

Commit

Permalink
add test for default argument of break_lot
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl committed Sep 10, 2024
1 parent eb7a451 commit e7d7205
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/trio/_core/_parking_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,13 @@ def repark_all(self, new_lot: ParkingLot) -> None:
"""
return self.repark(new_lot, count=len(self))

def break_lot(self, task: Task | None) -> None:
def break_lot(self, task: Task | None = None) -> None:
"""Break this lot, causing all parked tasks to raise an error, and any
future tasks attempting to park (and unpark? repark?) to error. The error
contains a reference to the task sent as a parameter.
"""
if task is None:
task = _core.current_task()
self.broken_by = task

for parked_task in self._parked:
Expand Down
3 changes: 3 additions & 0 deletions src/trio/_core/_tests/test_parking_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ async def test_parking_lot_breaker_basic() -> None:
):
trio.lowlevel.remove_parking_lot_breaker(task, lot)

lot.break_lot()
assert lot.broken_by == task


async def test_parking_lot_breaker() -> None:
async def bad_parker(lot: ParkingLot, scope: _core.CancelScope) -> None:
Expand Down

0 comments on commit e7d7205

Please sign in to comment.