'If the protocol created by L{SMTPSenderFactory} loses its connection
before receiving confirmation of message delivery, it reconnects and
tries to deliver the message again.'

def test_retryAfterDisconnect(self):

    recipient = 'alice'
    message = 'some    message    text'
    domain = DummyDomain([recipient])
    class CleanSMTP(smtp.SMTP, ):
        '\n                                                An    SMTP    subclass    which    ensures    that    its    transport    will    be\n                                                disconnected    before    the    test    ends.\n                                                '
        def makeConnection(innerSelf, transport):
            self.addCleanup(transport.loseConnection)
            smtp.SMTP.makeConnection(innerSelf, transport)
    serverFactory = MultipleDeliveryFactorySMTPServerFactory([BrokenMessage, (lambda user: DummyMessage(domain, user))])
    serverFactory.protocol = CleanSMTP
    serverPort = reactor.listenTCP(0, serverFactory, interface='127.0.0.1')
    serverHost = serverPort.getHost()
    self.addCleanup(serverPort.stopListening)
    sentDeferred = defer.Deferred()
    clientFactory = smtp.SMTPSenderFactory('bob@example.org', (recipient + '@example.com'), BytesIO(message), sentDeferred)
    clientFactory.domain = 'example.org'
    clientConnector = reactor.connectTCP(serverHost.host, serverHost.port, clientFactory)
    self.addCleanup(clientConnector.disconnect)
    def cbSent(ignored):
        '\n                                                Verify    that    the    message    was    successfully    delivered    and    flush    the\n                                                error    which    caused    the    first    attempt    to    fail.\n                                                '
        self.assertEqual(domain.messages, {recipient: [(('\n' + message) + '\n')]})
        self.assertEqual(len(self.flushLoggedErrors(RuntimeError)), 1)
    sentDeferred.addCallback(cbSent)
    return sentDeferred
