コード例 #1
0
ファイル: test_tub.py プロジェクト: pexip/os-foolscap
    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
コード例 #2
0
ファイル: test_discovery.py プロジェクト: public/foolscap
    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
コード例 #3
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
コード例 #4
0
ファイル: test_tub.py プロジェクト: pexip/os-foolscap
    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
コード例 #5
0
ファイル: test_tub.py プロジェクト: str4d/foolscap
 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
コード例 #6
0
ファイル: test_tub.py プロジェクト: str4d/foolscap
    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
コード例 #7
0
ファイル: test_tub.py プロジェクト: pexip/os-foolscap
    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
コード例 #8
0
ファイル: test_tub.py プロジェクト: pexip/os-foolscap
    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
コード例 #9
0
ファイル: test_tub.py プロジェクト: pexip/os-foolscap
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
コード例 #10
0
ファイル: test_tub.py プロジェクト: pexip/os-foolscap
    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
コード例 #11
0
ファイル: test_tub.py プロジェクト: str4d/foolscap
    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
コード例 #12
0
ファイル: test_tub.py プロジェクト: str4d/foolscap
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
コード例 #13
0
ファイル: test_tub.py プロジェクト: pexip/os-foolscap
class QueuedStartup(TargetMixin, unittest.TestCase):
    # calling getReference and connectTo before the Tub has started should
    # put off network activity until the Tub is started.

    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)

    def tearDown(self):
        d = TargetMixin.tearDown(self)

        def _more(res):
            return defer.DeferredList([s.stopService() for s in self.services])

        d.addCallback(_more)
        d.addCallback(flushEventualQueue)
        return d

    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

    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
コード例 #14
0
ファイル: test_tub.py プロジェクト: str4d/foolscap
class QueuedStartup(TargetMixin, unittest.TestCase):
    # calling getReference and connectTo before the Tub has started should
    # put off network activity until the Tub is started.

    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)

    def tearDown(self):
        d = TargetMixin.tearDown(self)
        def _more(res):
            return defer.DeferredList([s.stopService() for s in self.services])
        d.addCallback(_more)
        d.addCallback(flushEventualQueue)
        return d

    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

    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