Exemple #1
0
    def test_double_consumers(self):
        """ Check that two consumers can get messages. """
        obj = {'secret': secret}
        messages_received = []

        class TestConsumer1(moksha.api.hub.consumer.Consumer):
            topic = self.fq_topic

            def consume(self, message):
                messages_received.append(
                    message['body']['msg']
                )

        class TestConsumer2(moksha.api.hub.consumer.Consumer):
            topic = self.fq_topic

            def consume(self, message):
                messages_received.append(
                    message['body']['msg']
                )

        self.fake_register_consumer(TestConsumer1)
        self.fake_register_consumer(TestConsumer2)

        # Now, send a generic message to that topic, and see if the consumer
        # processed it.
        fedmsg.send_message(topic=self.topic, msg=obj)

        simulate_reactor(sleep_duration)
        sleep(sleep_duration)

        eq_(len(messages_received), 2)
        eq_(messages_received[0], obj)
        eq_(messages_received[1], obj)
Exemple #2
0
    def test_send_recv(self):
        """ Send a message and receive it.

        Admittedly, this is not a unit test, but an integration test.

        It tests:

            - Sending a message.
            - Receiving a message.
            - Encoding *and* decoding.

        """
        messages_received = []

        def callback(json):
            messages_received.append(fedmsg.json.loads(json.body))

        self.hub.subscribe(topic=self.fq_topic, callback=callback)
        sleep(sleep_duration)

        self.context.send_message(topic=self.topic, msg=secret)

        simulate_reactor(sleep_duration)
        sleep(sleep_duration)

        eq_(len(messages_received), 1)
        eq_(messages_received[0]['msg'], secret)
Exemple #3
0
    def test_double_consumers(self):
        """ Check that two consumers can get messages. """
        obj = {'secret': secret}
        messages_received = []

        class TestConsumer1(moksha.api.hub.consumer.Consumer):
            topic = self.fq_topic

            def consume(self, message):
                messages_received.append(message['body']['msg'])

        class TestConsumer2(moksha.api.hub.consumer.Consumer):
            topic = self.fq_topic

            def consume(self, message):
                messages_received.append(message['body']['msg'])

        self.fake_register_consumer(TestConsumer1)
        self.fake_register_consumer(TestConsumer2)

        # Now, send a generic message to that topic, and see if the consumer
        # processed it.
        fedmsg.send_message(topic=self.topic, msg=obj)

        simulate_reactor(sleep_duration)
        sleep(sleep_duration)

        eq_(len(messages_received), 2)
        eq_(messages_received[0], obj)
        eq_(messages_received[1], obj)
Exemple #4
0
    def test_send_recv(self):
        """ Send a message and receive it.

        Admittedly, this is not a unit test, but an integration test.

        It tests:

            - Sending a message.
            - Receiving a message.
            - Encoding *and* decoding.

        """
        messages_received = []

        def callback(json):
            messages_received.append(fedmsg.json.loads(json.body))

        self.hub.subscribe(topic=self.fq_topic, callback=callback)
        sleep(sleep_duration)

        self.context.send_message(topic=self.topic, msg=secret)

        simulate_reactor(sleep_duration)
        sleep(sleep_duration)

        eq_(len(messages_received), 1)
        eq_(messages_received[0]['msg'], secret)
Exemple #5
0
    def test_run_hub_get_heartbeat(self):
        """ Start the heartbeat producer and ensure it emits a message. """
        messages_received = []

        def callback(json):
            messages_received.append(fedmsg.json.loads(json.body))

        self.hub.subscribe(
            topic=HeartbeatProducer.topic,
            callback=callback,
        )

        simulate_reactor(HeartbeatProducer.frequency.seconds*1.1)
        sleep(HeartbeatProducer.frequency.seconds*1.1)

        eq_(len(messages_received), 1)
Exemple #6
0
    def test_run_hub_get_heartbeat(self):
        """ Start the heartbeat producer and ensure it emits a message. """
        messages_received = []

        def callback(json):
            messages_received.append(fedmsg.json.loads(json.body))

        self.hub.subscribe(
            topic=HeartbeatProducer.topic,
            callback=callback,
        )

        simulate_reactor(HeartbeatProducer.frequency.seconds * 1.1)
        sleep(HeartbeatProducer.frequency.seconds * 1.1)

        eq_(len(messages_received), 1)