Esempio n. 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)
Esempio n. 2
0
    def test_worker_creates_queue(self):
        sqs = SQSConnection(region=get_sqs_region('us-east-1'))

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

        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)
            all_queues = sqs.get_all_queues()
            self.assertEqual(len(all_queues), 1)

            self.assertEqual(
                all_queues[0].name,
                'test_events'
            )