'If the L{defer.Deferred} is manually cancelled before the timeout, it
is not re-cancelled (no L{AlreadyCancelled} error, and also no
canceling of inner deferreds), and the default C{onTimeoutCancel}
function is not called, preserving the original L{CancelledError}.'

def test_cancelBeforeTimeout(self):

    clock = Clock()
    d = defer.Deferred()
    d.addTimeout(10, clock)
    innerDeferred = defer.Deferred()
    dCanceled = [None]
    def onErrback(f):
        dCanceled[0] = f
        return innerDeferred
    d.addErrback(onErrback)
    d.cancel()
    self.assertIsInstance(dCanceled[0], failure.Failure)
    self.assertIs(dCanceled[0].type, defer.CancelledError)
    clock.advance(15)
    self.assertNoResult(innerDeferred)
