def test_mandatory_call(self):
        if not self.rpc_url.startswith("rabbit://"):
            self.skipTest("backend does not support call monitoring")

        transport = self.useFixture(
            utils.RPCTransportFixture(self.conf, self.rpc_url))
        target = oslo_messaging.Target(topic='topic_' + str(uuid.uuid4()),
                                       server='server_' + str(uuid.uuid4()))

        # test for mandatory flag using transport-options, see:
        # https://blueprints.launchpad.net/oslo.messaging/+spec/transport-options
        # first test with `at_least_once=False` raises a "MessagingTimeout"
        # error since there is no control if the queue actually exists.
        # (Default behavior)
        options = oslo_messaging.TransportOptions(at_least_once=False)
        client1 = utils.ClientStub(transport.transport,
                                   target,
                                   cast=False,
                                   timeout=1,
                                   transport_options=options)

        self.assertRaises(oslo_messaging.MessagingTimeout, client1.delay)

        # second test with `at_least_once=True` raises a "MessageUndeliverable"
        # caused by mandatory flag.
        # the MessageUndeliverable error is raised immediately without waiting
        # any timeout
        options2 = oslo_messaging.TransportOptions(at_least_once=True)
        client2 = utils.ClientStub(transport.transport,
                                   target,
                                   cast=False,
                                   timeout=60,
                                   transport_options=options2)

        self.assertRaises(oslo_messaging.MessageUndeliverable, client2.delay)
Example #2
0
    def test_endpoint_version_namespace(self):
        # verify endpoint version and namespace are checked
        target = oslo_messaging.Target(topic="topic_" + str(uuid.uuid4()),
                                       server="server_" + str(uuid.uuid4()),
                                       namespace="Name1",
                                       version="7.5")

        class _endpoint(object):
            def __init__(self, target):
                self.target = target()

            def test(self, ctxt, echo):
                return echo

        transport = self.useFixture(
            utils.RPCTransportFixture(self.conf, self.url))
        self.useFixture(
            utils.RpcServerFixture(self.conf,
                                   self.url,
                                   target,
                                   executor="threading",
                                   endpoint=_endpoint(target)))
        client1 = utils.ClientStub(transport.transport,
                                   target,
                                   cast=False,
                                   timeout=5)
        self.assertEqual("Hi there", client1.test(echo="Hi there"))

        # unsupported version
        target2 = target()
        target2.version = "7.6"
        client2 = utils.ClientStub(transport.transport,
                                   target2,
                                   cast=False,
                                   timeout=5)
        self.assertRaises(oslo_messaging.rpc.client.RemoteError,
                          client2.test,
                          echo="Expect failure")

        # no matching namespace
        target3 = oslo_messaging.Target(topic=target.topic,
                                        server=target.server,
                                        version=target.version,
                                        namespace="Name2")
        client3 = utils.ClientStub(transport.transport,
                                   target3,
                                   cast=False,
                                   timeout=5)
        self.assertRaises(oslo_messaging.rpc.client.RemoteError,
                          client3.test,
                          echo="Expect failure")
Example #3
0
    def test_timeout_with_concurrently_queues(self):
        transport = self.useFixture(utils.TransportFixture(
            self.conf, self.url))
        target = oslo_messaging.Target(topic="topic_" + str(uuid.uuid4()),
                                       server="server_" + str(uuid.uuid4()))
        server = self.useFixture(
            utils.RpcServerFixture(self.conf,
                                   self.url,
                                   target,
                                   executor="threading"))
        client = utils.ClientStub(transport.transport,
                                  target,
                                  cast=False,
                                  timeout=5)

        def short_periodical_tasks():
            for i in range(10):
                client.add(increment=1)
                time.sleep(1)

        with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
            future = executor.submit(client.long_running_task, seconds=10)
            executor.submit(short_periodical_tasks)
            self.assertRaises(oslo_messaging.MessagingTimeout, future.result)

        self.assertEqual(10, server.endpoint.ival)
Example #4
0
 def test_timeout(self):
     transport = self.useFixture(utils.TransportFixture(
         self.conf, self.url))
     target = oslo_messaging.Target(topic="no_such_topic")
     c = utils.ClientStub(transport.transport, target, timeout=1)
     self.assertThat(c.ping,
                     matchers.raises(oslo_messaging.MessagingTimeout))
Example #5
0
    def test_monitor_long_call(self):
        if not (self.url.startswith("rabbit://")
                or self.url.startswith("amqp://")):
            self.skipTest("backend does not support call monitoring")

        transport = self.useFixture(
            utils.RPCTransportFixture(self.conf, self.url))
        target = oslo_messaging.Target(topic='topic_' + str(uuid.uuid4()),
                                       server='server_' + str(uuid.uuid4()))

        class _endpoint(object):
            def delay(self, ctxt, seconds):
                time.sleep(seconds)
                return seconds

        self.useFixture(
            utils.RpcServerFixture(self.conf,
                                   self.url,
                                   target,
                                   executor='threading',
                                   endpoint=_endpoint()))

        # First case, no monitoring, ensure we timeout normally when the
        # server side runs long
        client1 = utils.ClientStub(transport.transport,
                                   target,
                                   cast=False,
                                   timeout=1)
        self.assertRaises(oslo_messaging.MessagingTimeout,
                          client1.delay,
                          seconds=4)

        # Second case, set a short call monitor timeout and a very
        # long overall timeout. If we didn't honor the call monitor
        # timeout, we would wait an hour, past the test timeout. If
        # the server was not sending message heartbeats, we'd time out
        # after two seconds.
        client2 = utils.ClientStub(transport.transport,
                                   target,
                                   cast=False,
                                   timeout=3600,
                                   call_monitor_timeout=2)
        self.assertEqual(4, client2.delay(seconds=4))