Exemplo n.º 1
0
 def test_election(self):
     c = self.Consumer()
     g = Gossip(c)
     g.start(c)
     g.election("id", "topic", "action")
     self.assertListEqual(g.consensus_replies["id"], [])
     g.dispatcher.send.assert_called_with("worker-elect", id="id", topic="topic", cver=1, action="action")
Exemplo n.º 2
0
 def test_election(self):
     c = self.Consumer()
     g = Gossip(c)
     g.start(c)
     g.election('id', 'topic', 'action')
     self.assertListEqual(g.consensus_replies['id'], [])
     g.dispatcher.send.assert_called_with(
         'worker-elect', id='id', topic='topic', cver=1, action='action',
     )
Exemplo n.º 3
0
 def test_election(self):
     c = self.Consumer()
     c.app.connection = _amqp_connection()
     g = Gossip(c)
     g.start(c)
     g.election('id', 'topic', 'action')
     self.assertListEqual(g.consensus_replies['id'], [])
     g.dispatcher.send.assert_called_with(
         'worker-elect', id='id', topic='topic', cver=1, action='action',
     )
Exemplo n.º 4
0
    def test_on_elect(self):
        c = self.Consumer()
        g = Gossip(c)
        g.start(c)

        event = self.Event('id1')
        g.on_elect(event)
        in_heap = g.consensus_requests['id1']
        self.assertTrue(in_heap)
        g.dispatcher.send.assert_called_with('worker-elect-ack', id='id1')

        event.pop('clock')
        with patch('celery.worker.consumer.error') as error:
            g.on_elect(event)
            self.assertTrue(error.called)
Exemplo n.º 5
0
    def test_on_elect(self):
        c = self.Consumer()
        g = Gossip(c)
        g.start(c)

        event = self.Event('id1')
        g.on_elect(event)
        in_heap = g.consensus_requests['id1']
        self.assertTrue(in_heap)
        g.dispatcher.send.assert_called_with('worker-elect-ack', id='id1')

        event.pop('clock')
        with patch('celery.worker.consumer.error') as error:
            g.on_elect(event)
            self.assertTrue(error.called)
Exemplo n.º 6
0
    def test_on_elect(self):
        c = self.Consumer()
        g = Gossip(c)
        g.start(c)

        event = self.Event("id1")
        g.on_elect(event)
        in_heap = g.consensus_requests["id1"]
        self.assertTrue(in_heap)
        g.dispatcher.send.assert_called_with("worker-elect-ack", id="id1")

        event.pop("clock")
        with patch("celery.worker.consumer.error") as error:
            g.on_elect(event)
            self.assertTrue(error.called)
Exemplo n.º 7
0
    def test_call_task(self):
        c = self.Consumer()
        g = Gossip(c)
        g.start(c)

        with patch('celery.worker.consumer.signature') as signature:
            sig = signature.return_value = Mock()
            task = Mock()
            g.call_task(task)
            signature.assert_called_with(task, app=c.app)
            sig.apply_async.assert_called_with()

            sig.apply_async.side_effect = MemoryError()
            with patch('celery.worker.consumer.error') as error:
                g.call_task(task)
                self.assertTrue(error.called)
Exemplo n.º 8
0
    def test_call_task(self):
        c = self.Consumer()
        g = Gossip(c)
        g.start(c)

        with patch('celery.worker.consumer.signature') as signature:
            sig = signature.return_value = Mock()
            task = Mock()
            g.call_task(task)
            signature.assert_called_with(task, app=c.app)
            sig.apply_async.assert_called_with()

            sig.apply_async.side_effect = MemoryError()
            with patch('celery.worker.consumer.error') as error:
                g.call_task(task)
                self.assertTrue(error.called)