Skip to content

Commit

Permalink
Add test for inlineCallbacks cancelling
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Jul 2, 2023
1 parent f1f94cb commit 3e78655
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/twisted/test/test_defer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
Union,
cast,
)
from unittest.mock import Mock

from hamcrest import assert_that, empty, equal_to, is_
from hypothesis import given
Expand Down Expand Up @@ -1682,6 +1683,26 @@ def test_fromCoroutineRequiresCoroutine(self) -> None:
for thing in thingsThatAreNotCoroutines:
self.assertRaises(defer.NotACoroutineError, Deferred.fromCoroutine, thing)

def test_inlineCallbacksCancel(self) -> None:
"""
Cancelling an inlineCallbacks Deferred propagates to the underlying
Deferred being waited on.
"""
cancellerMock = Mock()
d = Deferred(cancellerMock)

@defer.inlineCallbacks
def testFunc() -> Any:
yield d

funcD = testFunc()
self.assertFalse(funcD.called)

funcD.cancel()

cancellerMock.assert_called_once()
self.failureResultOf(funcD)

@pyunit.skipIf(_PYPY, "GC works differently on PyPy.")
def test_canceller_circular_reference_callback(self) -> None:
"""
Expand Down

0 comments on commit 3e78655

Please sign in to comment.