'Test that if the L{reconnecting} flag is passed with a True value then
a remote call made from a disconnection notification callback gets a
result successfully.'

def test_clientConnectionLost(self):

    class ReconnectOnce(pb.PBClientFactory, ):
        reconnectedAlready = False
        def clientConnectionLost(self, connector, reason):
            reconnecting = (not self.reconnectedAlready)
            self.reconnectedAlready = True
            result = pb.PBClientFactory.clientConnectionLost(self, connector, reason, reconnecting)
            if reconnecting:
                connector.connect()
            return result
    self.clientFactory = ReconnectOnce()
    self.establishClientAndServer()
    rootObjDeferred = self.clientFactory.getRootObject()
    def gotRootObject(rootObj):
        self.assertIsInstance(rootObj, pb.RemoteReference)
        d = Deferred()
        rootObj.notifyOnDisconnect(d.callback)
        self.clientFactory.disconnect()
        self.completeClientLostConnection()
        def disconnected(ign):
            d = self.clientFactory.getRootObject()
            def gotAnotherRootObject(anotherRootObj):
                self.assertIsInstance(anotherRootObj, pb.RemoteReference)
                d = Deferred()
                anotherRootObj.notifyOnDisconnect(d.callback)
                self.clientFactory.disconnect()
                self.completeClientLostConnection()
                return d
            return d.addCallback(gotAnotherRootObject)
        return d.addCallback(disconnected)
    return rootObjDeferred.addCallback(gotRootObject)
