'L{Deferred}s can have callbacks that themselves return L{Deferred}s.
When these "inner" L{Deferred}s fire (even asynchronously), the
callback chain continues.'

def test_nestedAsynchronousChainedDeferreds(self):

    results = []
    failures = []
    inner = defer.Deferred()
    def cb(result):
        results.append(('start-of-cb', result))
        d = defer.succeed('inner')
        def firstCallback(result):
            results.append(('firstCallback', 'inner'))
            return inner
        def secondCallback(result):
            results.append(('secondCallback', result))
            return (result * 2)
        d.addCallback(firstCallback).addCallback(secondCallback)
        d.addErrback(failures.append)
        return d
    outer = defer.succeed('outer')
    outer.addCallback(cb)
    outer.addCallback(results.append)
    self.assertEqual(results, [('start-of-cb', 'outer'), ('firstCallback', 'inner')])
    inner.callback('orange')
    inner.addErrback(failures.append)
    outer.addErrback(failures.append)
    self.assertEqual([], failures, "Got    errbacks    but    wasn't    expecting    any.")
    self.assertEqual(results, [('start-of-cb', 'outer'), ('firstCallback', 'inner'), ('secondCallback', 'orange'), 'orangeorange'])
