'When a L{Deferred} encounters a result which is another L{Deferred}
which is waiting on a third L{Deferred}, the middle L{Deferred}\'s
callbacks are executed after the third L{Deferred} fires and before the
first receives a result.'

def test_innerCallbacksPreserved(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)
    inner.callback('orange')
    outer.addCallback(results.append)
    inner.addErrback(failures.append)
    outer.addErrback(failures.append)
    self.assertEqual([], failures)
    self.assertEqual(results, [('start-of-cb', 'outer'), ('firstCallback', 'inner'), ('secondCallback', 'orange'), 'orangeorange'])
