def test_cache(self):
        c, s, pump = connectedServerAndClient()
        obj = NestedCache()
        obj2 = NestedComplicatedCache()
        vcc = obj2.c
        s.setNameForLocal("obj", obj)
        s.setNameForLocal("xxx", obj2)
        o2 = c.remoteForName("obj")
        o3 = c.remoteForName("xxx")
        coll = []
        o2.callRemote("getCache"
            ).addCallback(coll.append).addErrback(coll.append)
        o2.callRemote("getCache"
            ).addCallback(coll.append).addErrback(coll.append)
        complex = []
        o3.callRemote("getCache").addCallback(complex.append)
        o3.callRemote("getCache").addCallback(complex.append)
        pump.flush()
        # `worst things first'
        self.assertEquals(complex[0].x, 1)
        self.assertEquals(complex[0].y, 2)
        self.assertEquals(complex[0].foo, 3)

        vcc.setFoo4()
        pump.flush()
        self.assertEquals(complex[0].foo, 4)
        self.assertEquals(len(coll), 2)
        cp = coll[0][0]
        self.assertIdentical(cp.checkMethod().im_self, cp,
                             "potential refcounting issue")
        self.assertIdentical(cp.checkSelf(), cp,
                             "other potential refcounting issue")
        col2 = []
        o2.callRemote('putCache',cp).addCallback(col2.append)
        pump.flush()
        # The objects were the same (testing lcache identity)
        self.assertTrue(col2[0])
        # test equality of references to methods
        self.assertEquals(o2.remoteMethod("getCache"),
                          o2.remoteMethod("getCache"))

        # now, refcounting (similiar to testRefCount)
        luid = cp.luid
        baroqueLuid = complex[0].luid
        self.assertIn(luid, s.remotelyCachedObjects,
                      "remote cache doesn't have it")
        del coll
        del cp
        pump.flush()
        del complex
        del col2
        # extra nudge...
        pump.flush()
        # del vcc.observer
        # nudge the gc
        if sys.hexversion >= 0x2000000:
            gc.collect()
        # try to nudge the GC even if we can't really
        pump.flush()
        # The GC is done with it.
        self.assertNotIn(luid, s.remotelyCachedObjects,
                         "Server still had it after GC")
        self.assertNotIn(luid, c.locallyCachedObjects,
                         "Client still had it after GC")
        self.assertNotIn(baroqueLuid, s.remotelyCachedObjects,
                         "Server still had complex after GC")
        self.assertNotIn(baroqueLuid, c.locallyCachedObjects,
                         "Client still had complex after GC")
        self.assertIdentical(vcc.observer, None, "observer was not removed")
dataset/ETHPy150Open kuri65536/python-for-android/python-modules/twisted/twisted/test/test_pb.py/BrokerTestCase.test_cache/original