Example #1
0
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, ]
Example #2
0
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, ]
Example #3
0
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, ]
Example #4
0
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, ]
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), ]
Example #6
0
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,
    ]
Example #7
0
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,
    ]
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), ]
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), ]
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), ]
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), ]
Example #12
0
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,
    ]
Example #13
0
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,
    ]
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), ]
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), ]