Ejemplo n.º 1
0
 def test_set_location(self):
     t = GoodEnoughTub()
     t.listenOn("tcp:0")
     t.setServiceParent(self.s)
     t.setLocation("127.0.0.1:12345")
     # setLocation may only be called once
     self.failUnlessRaises(PBError, t.setLocation, "127.0.0.1:12345")
Ejemplo n.º 2
0
 def test_set_location(self):
     t = GoodEnoughTub()
     t.listenOn("tcp:0")
     t.setServiceParent(self.s)
     t.setLocation("127.0.0.1:12345")
     # setLocation may only be called once
     self.failUnlessRaises(PBError, t.setLocation, "127.0.0.1:12345")
Ejemplo n.º 3
0
class CancelPendingDeliveries(unittest.TestCase, StallMixin):
    def tearDown(self):
        dl = [defer.succeed(None)]
        if self.tubA.running:
            dl.append(defer.maybeDeferred(self.tubA.stopService))
        if self.tubB.running:
            dl.append(defer.maybeDeferred(self.tubB.stopService))
        d = defer.DeferredList(dl)
        d.addCallback(flushEventualQueue)
        return d

    def test_cancel_pending_deliveries(self):
        # when a Tub is stopped, any deliveries that were pending should be
        # discarded. TubA sends remote_one+remote_two (and we hope they
        # arrive in the same chunk). TubB responds to remote_one by shutting
        # down. remote_two should be discarded. The bug was that remote_two
        # would cause an unhandled error on the TubB side.
        self.tubA = GoodEnoughTub()
        self.tubB = GoodEnoughTub()
        self.tubA.startService()
        self.tubB.startService()

        self.tubB.listenOn("tcp:0")
        d = self.tubB.setLocationAutomatically()
        r = Receiver(self.tubB)
        d.addCallback(lambda res: self.tubB.registerReference(r))
        d.addCallback(lambda furl: self.tubA.getReference(furl))

        def _go(rref):
            # we want these two to get sent and received in the same hunk
            rref.callRemoteOnly("one")
            rref.callRemoteOnly("two")
            return r.done_d

        d.addCallback(_go)
        # let remote_two do its log.err before we move on to the next test
        d.addCallback(self.stall, 1.0)
        return d
Ejemplo n.º 4
0
class CancelPendingDeliveries(unittest.TestCase, StallMixin):
    def tearDown(self):
        dl = [defer.succeed(None)]
        if self.tubA.running:
            dl.append(defer.maybeDeferred(self.tubA.stopService))
        if self.tubB.running:
            dl.append(defer.maybeDeferred(self.tubB.stopService))
        d = defer.DeferredList(dl)
        d.addCallback(flushEventualQueue)
        return d

    def test_cancel_pending_deliveries(self):
        # when a Tub is stopped, any deliveries that were pending should be
        # discarded. TubA sends remote_one+remote_two (and we hope they
        # arrive in the same chunk). TubB responds to remote_one by shutting
        # down. remote_two should be discarded. The bug was that remote_two
        # would cause an unhandled error on the TubB side.
        self.tubA = GoodEnoughTub()
        self.tubB = GoodEnoughTub()
        self.tubA.startService()
        self.tubB.startService()

        self.tubB.listenOn("tcp:0")
        d = self.tubB.setLocationAutomatically()
        r = Receiver(self.tubB)
        d.addCallback(lambda res: self.tubB.registerReference(r))
        d.addCallback(lambda furl: self.tubA.getReference(furl))
        def _go(rref):
            # we want these two to get sent and received in the same hunk
            rref.callRemoteOnly("one")
            rref.callRemoteOnly("two")
            return r.done_d
        d.addCallback(_go)
        # let remote_two do its log.err before we move on to the next test
        d.addCallback(self.stall, 1.0)
        return d
Ejemplo n.º 5
0
 def test_referenceables_die(self):
     # serialized data will not keep the referenceable alive
     t1 = GoodEnoughTub()
     t1.setServiceParent(self.s)
     l = t1.listenOn("tcp:0:interface=127.0.0.1")
     t1.setLocation("127.0.0.1:%d" % l.getPortnum())
     r1 = Referenceable()
     t2 = GoodEnoughTub()
     t2.setServiceParent(self.s)
     obj = ("graph tangly", r1)
     d = t1.serialize(obj)
     del r1; del obj
     gc.collect()
     d.addCallback(lambda data:
                   self.shouldFail(KeyError, "test_referenceables_die",
                                   "unable to find reference for name",
                                   t2.unserialize, data))
     return d
Ejemplo n.º 6
0
 def test_set_location_automatically(self):
     t = GoodEnoughTub()
     l = t.listenOn("tcp:0")
     t.setServiceParent(self.s)
     d = t.setLocationAutomatically()
     d.addCallback(lambda res: t.registerReference(Referenceable()))
     def _check(furl):
         sr = SturdyRef(furl)
         portnum = l.getPortnum()
         if sr.encrypted:
             for lh in sr.locationHints:
                 self.failUnlessEqual(lh[2], portnum, lh)
             self.failUnless( ("tcp", "127.0.0.1", portnum)
                              in sr.locationHints)
         else:
             # TODO: unauthenticated tubs need review, I think they
             # deserve to have tubids and multiple connection hints
             pass
     d.addCallback(_check)
     return d
Ejemplo n.º 7
0
    def test_set_location_automatically(self):
        t = GoodEnoughTub()
        l = t.listenOn("tcp:0")
        t.setServiceParent(self.s)
        d = t.setLocationAutomatically()
        d.addCallback(lambda res: t.registerReference(Referenceable()))

        def _check(furl):
            sr = SturdyRef(furl)
            portnum = l.getPortnum()
            if sr.encrypted:
                for lh in sr.locationHints:
                    self.failUnlessEqual(lh[2], portnum, lh)
                self.failUnless(("ipv4", "127.0.0.1",
                                 portnum) in sr.locationHints)
            else:
                # TODO: unauthenticated tubs need review, I think they
                # deserve to have tubids and multiple connection hints
                pass

        d.addCallback(_check)
        return d
Ejemplo n.º 8
0
 def test_referenceable(self):
     t1 = GoodEnoughTub()
     t1.setServiceParent(self.s)
     l = t1.listenOn("tcp:0:interface=127.0.0.1")
     t1.setLocation("127.0.0.1:%d" % l.getPortnum())
     r1 = Referenceable()
     # the serialized blob can't keep the reference alive, so you must
     # arrange for that separately
     t1.registerReference(r1)
     t2 = GoodEnoughTub()
     t2.setServiceParent(self.s)
     obj = ("graph tangly", r1)
     d = t1.serialize(obj)
     del r1; del obj
     def _done(data):
         self.failUnless("their-reference" in data)
         return data
     d.addCallback(_done)
     d.addCallback(lambda data: t2.unserialize(data))
     def _check(obj2):
         self.failUnlessEqual(obj2[0], "graph tangly")
         self.failUnless(isinstance(obj2[1], RemoteReference))
     d.addCallback(_check)
     return d