Exemplo n.º 1
0
def test_queue():
    # Test queueing tasks.
    with patch('psq.queue.Queue._get_or_create_topic'):
        q = Queue(Mock())
        q.storage.put_task = Mock()

        r = q.enqueue(sum, 1, 2, arg='c')
        assert q.topic.publish.called
        assert q.storage.put_task.called

        t = q.storage.put_task.call_args[0][0]
        assert t.f == sum
        assert t.args == (1, 2)
        assert t.kwargs == {'arg': 'c'}

        assert r.task_id == t.id
Exemplo n.º 2
0
    def test_queue(self):
        # Test queueing tasks.
        with patch('psq.queue.Queue._get_or_create_topic'):
            q = Queue(Mock())
            q.storage.put_task = Mock()

            r = q.enqueue(sum, 1, 2, arg='c')
            assert q.topic.publish.called
            assert q.storage.put_task.called

            t = q.storage.put_task.call_args[0][0]
            assert t.f == sum
            assert t.args == (1, 2)
            assert t.kwargs == {'arg': 'c'}

            assert r.task_id == t.id
Exemplo n.º 3
0
def test_synchronous_fail():
    q = Queue(pubsub=None, storage=TestStorage(), async=False)
    r = q.enqueue(sum, "2")
    with pytest.raises(TypeError):
        r.result()
Exemplo n.º 4
0
def test_synchronous_success():
    q = Queue(pubsub=None, storage=TestStorage(), async=False)
    r = q.enqueue(sum, [1, 2])
    assert r.result() == 3
Exemplo n.º 5
0
def test_synchronous_fail():
    q = Queue(pubsub=None, storage=TestStorage(), async=False)
    r = q.enqueue(sum, "2")
    with pytest.raises(TypeError):
        r.result()
Exemplo n.º 6
0
def test_synchronous_success():
    q = Queue(pubsub=None, storage=TestStorage(), async=False)
    r = q.enqueue(sum, [1, 2])
    assert r.result() == 3
Exemplo n.º 7
0
def test_string_function():
    q = Queue(pubsub=None, storage=TestStorage(), async=False)
    r = q.enqueue('psq.queue_test.dummy_queue_func')
    assert r.result() == "Hello"