Esempio n. 1
0
    def test_basic_pubsub(self, settings):
        bus = PubSub()

        # Enable director to allow receiving messages
        bus.init_director()

        messages = []

        def callback(msg):
            messages.append(msg)
            bus.loop.stop()

        def send_message():
            api.publish('channel', 'type', {'test': 'works!'})
            time.sleep(1)
            api.publish('channel', 'type', {'test': 'works!'})

        subscriber = bus.get_subscriber(callback)
        assert bus.subscribe(subscriber, 'channel')

        proc = multiprocessing.Process(target=send_message)
        proc.start()

        bus.loop.start()

        proc.join()
        assert len(messages)
Esempio n. 2
0
 def setup(self, cm):
     self.pubsub = PubSub()
     self.context = cm.return_value