Exemplo 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
Exemplo n.º 2
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
Exemplo 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 = []
Exemplo 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
Exemplo 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 = {}
Exemplo 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")
Exemplo n.º 7
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
Exemplo n.º 8
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
Exemplo n.º 9
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)
Exemplo n.º 10
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)
Exemplo n.º 11
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")
Exemplo n.º 12
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
Exemplo n.º 13
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
Exemplo n.º 14
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
Exemplo 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
Exemplo n.º 16
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
Exemplo n.º 17
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
Exemplo n.º 18
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
Exemplo n.º 19
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
Exemplo n.º 20
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
Exemplo n.º 21
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)
Exemplo n.º 22
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
Exemplo n.º 23
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
Exemplo n.º 24
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
Exemplo n.º 25
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
Exemplo n.º 26
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
Exemplo n.º 27
0
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
Exemplo n.º 28
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
Exemplo n.º 29
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
Exemplo n.º 30
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
Exemplo n.º 31
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
Exemplo n.º 32
0
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
Exemplo n.º 33
0
 def setUp(self):
     self.services = [GoodEnoughTub()]
     self.services[0].startService()