Exemple #1
0
    def test_basis(self):
        # manager二つ使っているのでqueue nameは固定にしないと動かない
        queue = SyncManager(queue="dummy")
        worker_queue = AsyncManager(queue="dummy")
        self.addCleanup(queue.close_connection)
        # XXX こちらをcloseするとtesting のAsyncWorkerTestCase.doCleanupと競合しているのかエラーになるのでコメントアウト
#         self.addCleanup(worker_queue.close_connection)
        queue.connect(host=HOST)
        worker_queue.connect(host=HOST)

        counter = {"n": 0}
        def on_message(body):
            self.assertEqual(body, {"message": "Hello, world!"})
            counter["n"] += 1

        worker_queue.start_consuming(
            on_message,
        )

        queue.publish({"message": "Hello, world!"}, routing_key=queue.name)

        IOLoop.current().add_timeout(time() + 0.2, self.stop)
        self.wait()

        self.assertEqual(counter["n"], 1)
Exemple #2
0
 def test_publish_with_not_ready(self):
     queue = SyncManager(queue="dummy")
     self.addCleanup(queue.close_connection)
     queue.connect(host=HOST)
     queue._ready = False
     try:
         queue.publish(None,None)
     except Exception as e:
         self.fail("This exception is raised: {}".format(e))
Exemple #3
0
 def test_publish_with_not_ready(self):
     queue = SyncManager(queue="dummy")
     self.addCleanup(queue.close_connection)
     queue.connect(host=HOST)
     queue._ready = False
     try:
         queue.publish(None, None)
     except Exception as e:
         self.fail("This exception is raised: {}".format(e))
Exemple #4
0
    def test_ready_flag_when_queue_declere_completed(self):
        queue = SyncManager(queue="dummy")
        worker_queue = AsyncManager(queue="dummy")
        self.addCleanup(queue.close_connection)
        queue.connect(host=HOST)
        worker_queue.connect(host=HOST)

        def on_message():
            pass

        worker_queue.start_consuming(on_message)

        queue.publish({"message": "Hello, world!"}, routing_key=queue.name)
        IOLoop.current().add_timeout(time() + 0.2, self.stop)
        self.wait()
        self.assertTrue(queue._ready)
Exemple #5
0
    def test_ready_flag_when_queue_declere_completed(self):
        queue = SyncManager(queue="dummy")
        worker_queue = AsyncManager(queue="dummy")
        self.addCleanup(queue.close_connection)
        queue.connect(host=HOST)
        worker_queue.connect(host=HOST)

        def on_message():
            pass

        worker_queue.start_consuming(on_message, )

        queue.publish({"message": "Hello, world!"}, routing_key=queue.name)
        IOLoop.current().add_timeout(time() + 0.2, self.stop)
        self.wait()
        self.assertTrue(queue._ready)
Exemple #6
0
    def test_basis(self):
        # manager二つ使っているのでqueue nameは固定にしないと動かない
        queue = SyncManager(queue="dummy")
        worker_queue = AsyncManager(queue="dummy")
        self.addCleanup(queue.close_connection)
        # XXX こちらをcloseするとtesting のAsyncWorkerTestCase.doCleanupと競合しているのかエラーになるのでコメントアウト
        #         self.addCleanup(worker_queue.close_connection)
        queue.connect(host=HOST)
        worker_queue.connect(host=HOST)

        counter = {"n": 0}

        def on_message(body):
            self.assertEqual(body, {"message": "Hello, world!"})
            counter["n"] += 1

        worker_queue.start_consuming(on_message, )

        queue.publish({"message": "Hello, world!"}, routing_key=queue.name)

        IOLoop.current().add_timeout(time() + 0.2, self.stop)
        self.wait()

        self.assertEqual(counter["n"], 1)