'The depth of the call stack does not grow as more L{Deferred} instances
are chained together.'

def test_boundedStackDepth(self):

    def chainDeferreds(howMany):
        stack = []
        def recordStackDepth(ignored):
            stack.append(len(traceback.extract_stack()))
        top = defer.Deferred()
        innerDeferreds = [defer.Deferred() for ignored in range(howMany)]
        originalInners = innerDeferreds[:]
        last = defer.Deferred()
        inner = innerDeferreds.pop()
        top.addCallback((lambda ign, inner=inner: inner))
        top.addCallback(recordStackDepth)
        while innerDeferreds:
            newInner = innerDeferreds.pop()
            inner.addCallback((lambda ign, inner=newInner: inner))
            inner = newInner
        inner.addCallback((lambda ign: last))
        top.callback(None)
        for inner in originalInners:
            inner.callback(None)
        self.assertEqual(stack, [])
        last.callback(None)
        return stack[0]
    self.assertEqual(chainDeferreds(1), chainDeferreds(2))
