示例#1
0
        def test_async_basics(self):
                # test a simple async call with no parameters
                ac = AsyncCall()
                ac.start(self.__nop)
                ac.result()

                # test a simple async call with positional parameters
                ac = AsyncCall()
                ac.start(self.__add, 1, 2)
                rv = ac.result()
                self.assertEqual(rv, 3)

                # test a simple async call with keyword parameters
                ac = AsyncCall()
                ac.start(self.__add, x=1, y=2)
                rv = ac.result()
                self.assertEqual(rv, 3)

                # test async call with invalid arguments
                ac = AsyncCall()
                ac.start(self.__add, 1, 2, 3)
                self.assertRaisesRegexp(AsyncCallException,
                    "takes exactly 2 arguments",
                    ac.result)
                ac = AsyncCall()
                ac.start(self.__add, x=1, y=2, z=3)
                self.assertRaisesRegexp(AsyncCallException,
                    "got an unexpected keyword argument",
                    ac.result)
                ac = AsyncCall()
                ac.start(self.__add, y=2, z=3)
                self.assertRaisesRegexp(AsyncCallException,
                    "got an unexpected keyword argument",
                    ac.result)
示例#2
0
    def test_async_basics(self):
        # test a simple async call with no parameters
        ac = AsyncCall()
        ac.start(self.__nop)
        ac.result()

        # test a simple async call with positional parameters
        ac = AsyncCall()
        ac.start(self.__add, 1, 2)
        rv = ac.result()
        self.assertEqual(rv, 3)

        # test a simple async call with keyword parameters
        ac = AsyncCall()
        ac.start(self.__add, x=1, y=2)
        rv = ac.result()
        self.assertEqual(rv, 3)

        # test async call with invalid arguments
        ac = AsyncCall()
        ac.start(self.__add, 1, 2, 3)
        self.assertRaisesRegexp(AsyncCallException,
                                "takes exactly 2 arguments", ac.result)
        ac = AsyncCall()
        ac.start(self.__add, x=1, y=2, z=3)
        self.assertRaisesRegexp(AsyncCallException,
                                "got an unexpected keyword argument",
                                ac.result)
        ac = AsyncCall()
        ac.start(self.__add, y=2, z=3)
        self.assertRaisesRegexp(AsyncCallException,
                                "got an unexpected keyword argument",
                                ac.result)
示例#3
0
    def __server_setup_and_call(self,
                                method,
                                http_enc=True,
                                use_proc=True,
                                **kwargs):
        """Setup an rpc server and make a call to it.
                All calls are made asynchronously."""

        server_proc, client_rpc = self.__server_setup(http_enc=http_enc,
                                                      use_proc=use_proc)
        method_cb = getattr(client_rpc, method)
        ac = AsyncCall()
        ac.start(method_cb, **kwargs)

        # Destroying all references to the client object should close
        # the client end of our pipe to the server, which in turn
        # should cause the server to cleanly exit.  If we hang waiting
        # for the server to exist then that's a bug.
        del method_cb, client_rpc

        try:
            rv = ac.result()
        except AsyncCallException as ex:
            # we explicity delete the client rpc object to try and
            # ensure that any connection to the server process
            # gets closed (so that the server process exits).
            server_proc.join()
            raise

        server_proc.join()
        return rv
示例#4
0
        def __server_setup_and_call(self, method, http_enc=True,
            use_proc=True, **kwargs):
                """Setup an rpc server and make a call to it.
                All calls are made asynchronously."""

                server_proc, client_rpc = self.__server_setup(
                    http_enc=http_enc, use_proc=use_proc)
                method_cb = getattr(client_rpc, method)
                ac = AsyncCall()
                ac.start(method_cb, **kwargs)

                # Destroying all references to the client object should close
                # the client end of our pipe to the server, which in turn
                # should cause the server to cleanly exit.  If we hang waiting
                # for the server to exist then that's a bug.
                del method_cb, client_rpc

                try:
                        rv = ac.result()
                except AsyncCallException, ex:
                        # we explicity delete the client rpc object to try and
                        # ensure that any connection to the server process
                        # gets closed (so that the server process exits).
                        server_proc.join()
                        raise