Ejemplo n.º 1
0
    def test_mdns(self):
        """ Check that we can actually publish a Tub
        and read it back again.
        """

        tub = GoodEnoughTub()
        self.startTub(tub)
        tub.setLocation("mdns-sd")
        
        target = HelperTarget()

        furl = tub.registerReference(target)
        print furl
        
        rtub = GoodEnoughTub()
        self.startTub(rtub)
        d = rtub.getReference(furl)
        def _connected(ref):
            return ref.callRemote("set", furl)
        d.addCallback(_connected)
        
        def _check(res):
            self.failUnlessEqual(target.obj, furl)
        d.addCallback(_check)
        
        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 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.º 4
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.º 5
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.º 6
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("") # this is how you say "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)
        d.addBoth(_check)
        return d
Ejemplo n.º 7
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.º 8
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.º 9
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.º 10
0
    def test_future(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)

        # "future:stuff" 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("future:stuff")
        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)
        d.addBoth(_check)
        return d
Ejemplo n.º 11
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