Ejemplo n.º 1
0
    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.º 2
0
    def test_unrouteable(self):
        # bug #129: a FURL with no location hints causes a synchronous
        # exception in Tub.getReference(), instead of an errback'ed Deferred.

        tubA = GoodEnoughTub()
        tubA.setServiceParent(self.s)
        tubB = GoodEnoughTub()
        tubB.setServiceParent(self.s)

        # "-unrouteable-" is interpreted as a "location hint format from the
        # future", which we're supposed to ignore, and are thus left with no
        # hints
        tubB.setLocation("-unrouteable-")
        r = Receiver(tubB)
        furl = tubB.registerReference(r)
        # the buggy behavior is that the following call raises an exception
        d = tubA.getReference(furl)
        # whereas it ought to return a Deferred
        self.failUnless(isinstance(d, defer.Deferred))

        def _check(f):
            self.failUnless(isinstance(f, failure.Failure), f)
            self.failUnless(f.check(NoLocationHintsError),
                            f)  # unparseable FURL

        d.addBoth(_check)
        return d
Ejemplo n.º 3
0
 def setUp(self):
     self.services = [GoodEnoughTub(), GoodEnoughTub()]
     self.tubA, self.tubB = self.services
     self.tub_ports = []
     for s in self.services:
         s.startService()
         l = s.listenOn("tcp:0:interface=127.0.0.1")
         s.setLocation("127.0.0.1:%d" % l.getPortnum())
         self.tub_ports.append(l.getPortnum())
     self._log_observers_to_remove = []
Ejemplo n.º 4
0
 def setUp(self):
     s0, s1 = self.services = [GoodEnoughTub(), GoodEnoughTub()]
     s0.brokerClass = PingCountingBroker
     s1.brokerClass = PingCountingBroker
     s0.startService()
     s1.startService()
     l = s0.listenOn("tcp:0:interface=127.0.0.1")
     s0.setLocation("127.0.0.1:%d" % l.getPortnum())
     self.target = TargetWithoutInterfaces()
     public_url = s0.registerReference(self.target, "target")
     self.public_url = public_url
Ejemplo n.º 5
0
 def setUp(self):
     TargetMixin.setUp(self)
     self.tubA, self.tubB = [GoodEnoughTub(), GoodEnoughTub()]
     self.services = [self.tubA, self.tubB]
     self.tubA.startService()
     self.tubB.startService()
     l = self.tubB.listenOn("tcp:0:interface=127.0.0.1")
     self.tubB.setLocation("127.0.0.1:%d" % l.getPortnum())
     self.url_on_b = self.tubB.registerReference(Referenceable())
     self.lookups = []
     self.lookups2 = []
     self.names = {}
     self.names2 = {}
Ejemplo n.º 6
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.º 7
0
 def setUp(self):
     self.services = [GoodEnoughTub() for i in range(4)]
     self.tubA, self.tubB, self.tubC, self.tubD = self.services
     for s in self.services:
         s.startService()
         l = s.listenOn("tcp:0:interface=127.0.0.1")
         loc = "127.0.0.1:%d" % l.getPortnum()
         s.setLocation(loc)
Ejemplo n.º 8
0
 def getRef(self, target):
     self.services.append(GoodEnoughTub())
     s1 = self.services[0]
     s2 = self.services[1]
     s2.startService()
     l = s1.listenOn("tcp:0:interface=127.0.0.1")
     s1.setLocation("127.0.0.1:%d" % l.getPortnum())
     public_url = s1.registerReference(target, "target")
     self.public_url = public_url
     d = s2.getReference(public_url)
     return d
Ejemplo n.º 9
0
    def test_empty_location2(self):
        tubA = GoodEnoughTub()
        tubA.setServiceParent(self.s)
        tubB = GoodEnoughTub()
        tubB.setServiceParent(self.s)

        # "," is two empty locations. This passes the regexp, unlike "".
        tubB.setLocation(",")
        r = Receiver(tubB)
        furl = tubB.registerReference(r)
        # the buggy behavior is that the following call raises an exception
        d = tubA.getReference(furl)
        # whereas it ought to return a Deferred
        self.failUnless(isinstance(d, defer.Deferred))

        def _check(f):
            self.failUnless(isinstance(f, failure.Failure), f)
            self.failUnless(f.check(NoLocationHintsError),
                            f)  # unparseable FURL

        d.addBoth(_check)
        return d
Ejemplo n.º 10
0
    def test_empty_location(self):
        # bug #129: a FURL with no location hints causes a synchronous
        # exception in Tub.getReference(), instead of an errback'ed Deferred.

        tubA = GoodEnoughTub()
        tubA.setServiceParent(self.s)
        tubB = GoodEnoughTub()
        tubB.setServiceParent(self.s)

        tubB.setLocation("")
        r = Receiver(tubB)
        furl = tubB.registerReference(r)
        # the buggy behavior is that the following call raises an exception
        d = tubA.getReference(furl)
        # whereas it ought to return a Deferred
        self.failUnless(isinstance(d, defer.Deferred))

        def _check(f):
            self.failUnless(isinstance(f, failure.Failure), f)
            self.failUnless(f.check(ValueError), f)  # unparseable FURL

        d.addBoth(_check)
        return d
Ejemplo n.º 11
0
 def test_doublestop(self):
     tub = GoodEnoughTub()
     tub.startService()
     d = tub.stopService()
     d.addCallback(lambda res: self.shouldFail(
         RuntimeError, "test_doublestop_startService",
         "Sorry, but Tubs cannot be restarted", tub.startService))
     d.addCallback(lambda res: self.shouldFail(
         RuntimeError, "test_doublestop_getReference",
         "Sorry, but this Tub has been shut down", tub.getReference, "furl")
                   )
     d.addCallback(lambda res: self.shouldFail(
         RuntimeError, "test_doublestop_connectTo",
         "Sorry, but this Tub has been shut down", tub.connectTo, "furl",
         None))
     return d
Ejemplo n.º 12
0
    def setUp(self):
        TargetMixin.setUp(self)
        self.tubB = GoodEnoughTub()
        self.services = [self.tubB]
        for s in self.services:
            s.startService()
            l = s.listenOn("tcp:0:interface=127.0.0.1")
            s.setLocation("127.0.0.1:%d" % l.getPortnum())

        self.barry = HelperTarget("barry")
        self.barry_url = self.tubB.registerReference(self.barry)

        self.bill = HelperTarget("bill")
        self.bill_url = self.tubB.registerReference(self.bill)

        self.bob = HelperTarget("bob")
        self.bob_url = self.tubB.registerReference(self.bob)
Ejemplo n.º 13
0
    def test_queued_getref(self):
        t1 = GoodEnoughTub()
        d1 = t1.getReference(self.barry_url)
        d2 = t1.getReference(self.bill_url)

        def _check(res):
            ((barry_success, barry_rref), (bill_success, bill_rref)) = res
            self.failUnless(barry_success)
            self.failUnless(bill_success)
            self.failUnless(isinstance(barry_rref, RemoteReference))
            self.failUnless(isinstance(bill_rref, RemoteReference))
            self.failIf(barry_rref == bill_success)

        dl = defer.DeferredList([d1, d2])
        dl.addCallback(_check)
        self.services.append(t1)
        eventually(t1.startService)
        return dl
Ejemplo n.º 14
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.º 15
0
    def test_queued_reconnector(self):
        t1 = GoodEnoughTub()
        bill_connections = []
        barry_connections = []
        t1.connectTo(self.bill_url, bill_connections.append)
        t1.connectTo(self.barry_url, barry_connections.append)

        def _check():
            if len(bill_connections) >= 1 and len(barry_connections) >= 1:
                return True
            return False

        d = self.poll(_check)

        def _validate(res):
            self.failUnless(isinstance(bill_connections[0], RemoteReference))
            self.failUnless(isinstance(barry_connections[0], RemoteReference))
            self.failIf(bill_connections[0] == barry_connections[0])

        d.addCallback(_validate)
        self.services.append(t1)
        eventually(t1.startService)
        return d
Ejemplo n.º 16
0
 def setUp(self):
     self.services = [GoodEnoughTub()]
     self.services[0].startService()