'After the connection a protocol is being used for is closed, the
reactor discards all of its references to the protocol.'

def test_protocolGarbageAfterLostConnection(self):

    lostConnectionDeferred = Deferred()
    clientProtocol = ClosingLaterProtocol(lostConnectionDeferred)
    clientRef = ref(clientProtocol)
    reactor = self.buildReactor()
    portDeferred = self.endpoints.server(reactor).listen(ServerFactory.forProtocol(Protocol))
    def listening(port):
        msg(('Listening    on    %r' % (port.getHost(),)))
        endpoint = self.endpoints.client(reactor, port.getHost())
        client = endpoint.connect(ClientFactory.forProtocol((lambda : clientProtocol)))
        def disconnect(proto):
            msg(('About    to    disconnect    %r' % (proto,)))
            proto.transport.loseConnection()
        client.addCallback(disconnect)
        client.addErrback(lostConnectionDeferred.errback)
        return lostConnectionDeferred
    def onListening():
        portDeferred.addCallback(listening)
        portDeferred.addErrback(err)
        portDeferred.addBoth((lambda ignored: reactor.stop()))
    needsRunningReactor(reactor, onListening)
    self.runReactor(reactor)
    clientProtocol = None
    collect()
    self.assertIsNone(clientRef())
