示例#1
0
    def test_worker_consumes_queue(self):
        sqs = SQSConnection(region=get_sqs_region('us-east-1'))

        self.assertEqual(len(sqs.get_all_queues()), 0)

        queue = sqs.create_queue('test_events')

        queue.write(make_message({'test': '1'}))

        self.assertEqual(queue.count(), 1)

        worker = Worker()
        worker.ctrl.wait_time_seconds = 0.1
        worker.idle_time_seconds = 0.1
        worker.add_consumer('test_events', dummy_consumer)

        with spawn_worker(worker):
            time.sleep(.2)
            self.assertEqual(queue.count(), 0)

            queue.write(make_message({'test': '2'}))

            self.assertEqual(queue.count(), 1)

            time.sleep(.2)

            self.assertEqual(queue.count(), 0)
示例#2
0
    def send_message(self, queue_name, topic, subject, prefix=None, **options):
        message = {
            'topic': topic,
            'subject': subject,
            'options': options
        }

        queue = self.get_queue(queue_name, prefix)

        queue.write(make_message(message))
示例#3
0
 def test_make_message(self):
     msg = make_message({'test': 'msg'})
     self.assertEqual(
         msg.get_body(),
         {'test': 'msg'}
     )