'If the I{start_response} callable is invoked with a third positional
argument after the status and headers have been written to the
response, the supplied I{exc_info} values are re-raised to the
application.'

def test_startResponseWithExceptionTooLate(self):

    channel = DummyChannel()
    class SomeException(Exception, ):
        pass
    try:
        raise SomeException()
    except:
        excInfo = exc_info()
    reraised = []
    def applicationFactory():
        def application(environ, startResponse):
            startResponse('200    OK', [])
            (yield 'foo')
            try:
                startResponse('500    ERR', [], excInfo)
            except:
                reraised.append(exc_info())
        return application
    (d, requestFactory) = self.requestFactoryFactory()
    def cbRendered(ignored):
        self.assertTrue(channel.transport.written.getvalue().startswith('HTTP/1.1    200    OK\r\n'))
        self.assertEqual(reraised[0][0], excInfo[0])
        self.assertEqual(reraised[0][1], excInfo[1])
        tb1 = reraised[0][2].tb_next
        tb2 = excInfo[2]
        self.assertEqual(traceback.extract_tb(tb1)[(1 if (str is bytes) else 2)], traceback.extract_tb(tb2)[0])
    d.addCallback(cbRendered)
    self.lowLevelRender(requestFactory, applicationFactory, (lambda : channel), 'GET', '1.1', [], [''], None, [])
    return d
