Exemplo n.º 1
0
    def test_call_return_nested(self):
        limit = 4
        calls = []

        class Object(cap.LocalObject):

            def __init__(self, name):
                self._name = name
                self.other = None

            def cap_call(self, args):
                calls.append("call %s" % self._name)
                if len(calls) < limit:
                    self.other.cap_call(("body", (), ()))
                calls.append("return %s" % self._name)
                return ("body", (), ())

        a = Object("a")
        b = Object("b")
        loop = self.make_event_loop()
        loop.once = loop.once_safely # Should really apply this for all tests
        sock1, sock2 = self.socketpair()
        [b_imported] = cap.make_connection(loop, sock1, [a], 1)
        [a_imported] = cap.make_connection(loop, sock2, [b], 1)
        a.other = b_imported
        b.other = a_imported
        result = a_imported.cap_call(("body", (), ()))
        self.assertEquals(calls,
                          ["call a", "call b", "call a", "call b",
                           "return b", "return a", "return b", "return a"])
        # Break "distributed" cycle
        a.other = None
        b.other = None
Exemplo n.º 2
0
 def test_sending_and_receiving(self):
     loop = self.make_event_loop()
     sock1, sock2 = self.socketpair()
     exported_objects = [CallLogger() for i in range(10)]
     cap.make_connection(loop, sock1, exported_objects)
     imported_objects = cap.make_connection(loop, sock2, [], 10)
     # Should work for any sequence of valid indexes
     for index in (0, 1, 1, 2):
         msg = ("some data for the body", (), ())
         imported_objects[index].cap_invoke(msg)
         loop.run_awhile()
         self.assertEquals(exported_objects[index].calls,
                           [("cap_invoke", (msg,))])
         exported_objects[index].calls[:] = []
Exemplo n.º 3
0
    def test_call_return(self):
        calls = []
        class Object(cap.LocalObject):
            def cap_call(self, args):
                calls.append(args)
                return ("result body", (), ())

        loop = self.make_event_loop()
        loop.once = loop.once_safely # Should really apply this for all tests
        sock1, sock2 = self.socketpair()
        cap.make_connection(loop, sock1, [Object()])
        [imported] = cap.make_connection(loop, sock2, [], 1)
        result = imported.cap_call(("args body", (), ()))
        self.assertEquals(calls, [("args body", (), ())])
        self.assertEquals(result, ("result body", (), ()))
Exemplo n.º 4
0
 def make_connection(self, *args, **kwargs):
     return cap.make_connection(*args, **kwargs)