'If a L{RemoteReference} to an L{IPerspective} avatar is decrefed and
there remain no other references to the avatar on the server, the
avatar is garbage collected and the logout method called.'

def test_logoutAfterDecref(self):

    loggedOut = Deferred()
    class EventPerspective(pb.Avatar, ):
        '\n                                                An    avatar    which    fires    a    Deferred    when    it    is    logged    out.\n                                                '
        def __init__(self, avatarId):
            pass
        def logout(self):
            loggedOut.callback(None)
    self.realm.perspectiveFactory = EventPerspective
    self.portal.registerChecker(checkers.InMemoryUsernamePasswordDatabaseDontUse(foo='bar'))
    d = self.clientFactory.login(credentials.UsernamePassword('foo', 'bar'), 'BRAINS!')
    def cbLoggedIn(avatar):
        return loggedOut
    d.addCallback(cbLoggedIn)
    def cbLoggedOut(ignored):
        self.assertEqual(self.serverFactory.protocolInstance._localCleanup, {})
    d.addCallback(cbLoggedOut)
    self.establishClientAndServer()
    self.pump.flush()
    gc.collect()
    self.pump.flush()
    return d
