'If a producer is unregistered from a transport after the transport has
been disconnected (by the peer) and after C{loseConnection} has been
called, the transport is not re-added to the reactor as a writer as
would be necessary if the transport were still connected.'

def test_unregisterProducerAfterDisconnect(self):

    reactor = self.buildReactor()
    self.listen(reactor, ServerFactory.forProtocol(ClosingProtocol))
    finished = Deferred()
    finished.addErrback(log.err)
    finished.addCallback((lambda ign: reactor.stop()))
    writing = []
    class ClientProtocol(Protocol, ):
        '\n                                                Protocol    to    connect,    register    a    producer,    try    to    lose    the\n                                                connection,    wait    for    the    server    to    disconnect    from    us,    and    then\n                                                unregister    the    producer.\n                                                '
        def connectionMade(self):
            log.msg('ClientProtocol.connectionMade')
            self.transport.registerProducer(_SimplePullProducer(self.transport), False)
            self.transport.loseConnection()
        def connectionLost(self, reason):
            log.msg('ClientProtocol.connectionLost')
            self.unregister()
            writing.append((self.transport in _getWriters(reactor)))
            finished.callback(None)
        def unregister(self):
            log.msg('ClientProtocol    unregister')
            self.transport.unregisterProducer()
    clientFactory = ClientFactory()
    clientFactory.protocol = ClientProtocol
    self.connect(reactor, clientFactory)
    self.runReactor(reactor)
    self.assertFalse(writing[0], 'Transport    was    writing    after    unregisterProducer.')
