コード例 #1
0
ファイル: test_worker.py プロジェクト: sebheinz/queue_utils
def test_basic_worker():
    channel = InputOutputEndpoint()
    w = Worker(channel, identity_work_method)
    w.start()

    channel.push("TEST")

    assert channel.pull() == ["TEST", ]
    assert channel._acks == [True, ]
コード例 #2
0
ファイル: test_worker.py プロジェクト: sebheinz/queue_utils
def test_forward_payload_error():
    channel = InputOutputEndpoint()
    w = Worker(channel, work_method)
    w.start()

    error_payload = {"error": "Some error", }
    channel.push(error_payload)

    assert channel.pull() == [error_payload, ]
    assert channel._acks == [True, ]
コード例 #3
0
ファイル: test_worker.py プロジェクト: sebheinz/queue_utils
def test_error_field_with_no_error():
    channel = InputOutputEndpoint()
    w = Worker(channel, work_method)
    w.start()

    error_payload = {"error": {}, }
    channel.push(error_payload)

    assert channel.pull() == ["WORKED", ]
    assert channel._acks == [True, ]
コード例 #4
0
def test_add_error():

    w = Worker('test', None, None, None)

    payload = {}
    error_payload = w.add_error(payload, invalid_payload_error)

    expected = {'error': {'test': [invalid_payload_error, ]}}

    assert expected == error_payload
コード例 #5
0
def test_add_none_error_adds_no_error():

    w = Worker('test', None, None, None)

    payload = {}
    error_payload = w.add_error(payload, None)

    expected = {}

    assert expected == error_payload
コード例 #6
0
ファイル: test_worker.py プロジェクト: sebheinz/queue_utils
def test_invalid_payload_sends_error_and_nacks():

    channel = InputOutputEndpoint()
    w = Worker(channel, identity_work_method, all_payloads_are_invalid)
    w.start()

    channel.push("TEST")

    assert channel.pull() == [invalid_payload_error, ]
    assert channel._acks == [False, ]
コード例 #7
0
def test_forward_payload_error():
    channel = InputOutputEndpoint()
    w = Worker('test', channel, channel, work_method)
    w.start_consuming()

    error_payload = {"error": "Some error", }
    channel.push(error_payload)

    assert channel.pull() == [error_payload, ]
    assert channel._acks == [(None, True), ]
コード例 #8
0
ファイル: test_worker.py プロジェクト: sebheinz/queue_utils
def test_basic_worker():
    channel = InputOutputEndpoint()
    w = Worker(channel, identity_work_method)
    w.start()

    channel.push("TEST")

    assert channel.pull() == [
        "TEST",
    ]
    assert channel._acks == [
        True,
    ]
コード例 #9
0
def test_not_producer_does_not_send():

    channel = InputOutputEndpoint()
    w = Worker('test', channel, None, work_method)
    w.start_consuming()

    assert not w.is_producer()

    channel.push("TEST")

    results = channel.pull()

    assert len(results) == 0
    assert channel._acks == [(None, True), ]
コード例 #10
0
ファイル: test_worker.py プロジェクト: sebheinz/queue_utils
def test_invalid_payload_sends_error_and_nacks():

    channel = InputOutputEndpoint()
    w = Worker(channel, identity_work_method, all_payloads_are_invalid)
    w.start()

    channel.push("TEST")

    assert channel.pull() == [
        invalid_payload_error,
    ]
    assert channel._acks == [
        False,
    ]
コード例 #11
0
def test_error_field_with_no_error():
    channel = InputOutputEndpoint()
    w = Worker('test', channel, channel, work_method)
    w.start_consuming()

    error_payload = {"error": {}, }
    channel.push(error_payload)

    results = channel.pull()

    assert len(results) == 1
    assert results[0]['input'] == error_payload
    assert results[0]['output'] == "WORKED"
    assert 'trace' in results[0]
    assert channel._acks == [(None, True), ]
コード例 #12
0
def test_basic_worker():
    channel = InputOutputEndpoint()
    w = Worker('test', channel, channel, work_method)
    w.start_consuming()

    channel.push("TEST")

    results = channel.pull()

    assert len(results) == 1

    assert results[0]['input'] == "TEST"
    assert results[0]['output'] == "WORKED"
    assert 'trace' in results[0]
    assert channel._acks == [(None, True), ]
コード例 #13
0
def test_work_error_forwards_error_and_nacks():
    channel = InputOutputEndpoint()
    w = Worker('test', channel, channel, work_error_method)
    w.start_consuming()

    channel.push("TEST")

    results = channel.pull()

    assert results[0]['error']['test'] == [work_error, ]
    assert 'input' in results[0]
    assert 'output' in results[0]
    assert 'trace' in results[0]

    assert channel._acks == [(None, False), ]
コード例 #14
0
ファイル: test_worker.py プロジェクト: sebheinz/queue_utils
def test_error_field_with_no_error():
    channel = InputOutputEndpoint()
    w = Worker(channel, work_method)
    w.start()

    error_payload = {
        "error": {},
    }
    channel.push(error_payload)

    assert channel.pull() == [
        "WORKED",
    ]
    assert channel._acks == [
        True,
    ]
コード例 #15
0
ファイル: test_worker.py プロジェクト: sebheinz/queue_utils
def test_forward_payload_error():
    channel = InputOutputEndpoint()
    w = Worker(channel, work_method)
    w.start()

    error_payload = {
        "error": "Some error",
    }
    channel.push(error_payload)

    assert channel.pull() == [
        error_payload,
    ]
    assert channel._acks == [
        True,
    ]
コード例 #16
0
def test_send_exception_does_not_acknowledge():
    class BrokenOutput(InputOutputEndpoint):

        def send_to_output(self, payload):
            raise Exception("BrokenOutput")

    channel = BrokenOutput()

    w = Worker('test', channel, channel, work_method)
    w.start_consuming()

    channel.push("TEST")

    results = channel.pull()

    assert len(results) == 0
    assert channel._acks == []
コード例 #17
0
def test_invalid_payload_sends_error_and_nacks():

    channel = InputOutputEndpoint()
    w = Worker('test', channel, channel, work_method, all_payloads_are_invalid)
    w.start_consuming()

    channel.push({'data': "TEST"})

    results = channel.pull()

    assert len(results) == 1
    assert results[0]['error']['test'] == [invalid_payload_error, ]
    assert 'input' not in results[0]
    assert 'output' not in results[0]
    assert 'trace' in results[0]

    assert channel._acks == [(None, False), ]
コード例 #18
0
def test_method_with_delivery_tag():
    class Method:
        delivery_tag = 99

    channel = InputOutputEndpoint()
    w = Worker('test', channel, channel, work_method)
    w.start_consuming()

    channel.push("TEST", method=Method())

    results = channel.pull()

    assert len(results) == 1
    assert results[0]['input'] == "TEST"
    assert results[0]['output'] == "WORKED"
    assert 'trace' in results[0]

    assert channel._acks == [(99, True), ]
コード例 #19
0
def test_add_field_for_string_payload():
    w = Worker('test', None, None, None)

    payload = w.add_field('payload', 'some_field', 'some_value')
    assert payload == 'payload'
コード例 #20
0
def test_check_field_for_string_payload():
    w = Worker('test', None, None, None)

    payload = w.check_field('payload', 'some_field')
    assert payload == 'payload'