Exemple #1
0
def test_worker_context_gets_stack(container_factory):
    context_cls = worker_context_factory()

    class FooService(object):
        name = 'baz'

    container = container_factory(FooService, {})
    service = FooService()

    context = context_cls(container, service, DummyProvider("bar"))
    assert context.call_id == 'baz.bar.0'
    assert context.call_id_stack == ['baz.bar.0']
    assert context.parent_call_stack == []

    # Build stack
    context = context_cls(container,
                          service,
                          DummyProvider("foo"),
                          data={'call_id_stack': context.call_id_stack})
    assert context.call_id == 'baz.foo.1'
    assert context.call_id_stack == ['baz.bar.0', 'baz.foo.1']

    # Long stack
    many_ids = [str(i) for i in xrange(10)]
    context = context_cls(container,
                          service,
                          DummyProvider("long"),
                          data={'call_id_stack': many_ids})
    expected = many_ids + ['baz.long.2']
    assert context.call_id_stack == expected
Exemple #2
0
def test_worker_context_gets_stack(container_factory):
    context_cls = worker_context_factory()

    class FooService(object):
        name = 'baz'

    container = container_factory(FooService, {})
    service = FooService()

    context = context_cls(container, service, DummyProvider("bar"))
    assert context.call_id == 'baz.bar.0'
    assert context.call_id_stack == ['baz.bar.0']
    assert context.parent_call_stack == []

    # Build stack
    context = context_cls(container, service, DummyProvider("foo"),
                          data={'call_id_stack': context.call_id_stack})
    assert context.call_id == 'baz.foo.1'
    assert context.call_id_stack == ['baz.bar.0', 'baz.foo.1']

    # Long stack
    many_ids = [str(i) for i in xrange(10)]
    context = context_cls(container, service, DummyProvider("long"),
                          data={'call_id_stack': many_ids})
    expected = many_ids + ['baz.long.2']
    assert context.call_id_stack == expected
Exemple #3
0
def test_short_call_stack(container_factory):
    context_cls = worker_context_factory()

    class FooService(object):
        name = 'baz'

    container = container_factory(FooService, {PARENT_CALLS_CONFIG_KEY: 1})
    service = FooService()

    # Trim stack
    many_ids = [str(i) for i in xrange(100)]
    context = context_cls(container, service, DummyProvider("long"),
                          data={'call_id_stack': many_ids})
    assert context.call_id_stack == ['99', 'baz.long.0']
Exemple #4
0
def test_short_call_stack(container_factory):
    context_cls = worker_context_factory()

    class FooService(object):
        name = 'baz'

    container = container_factory(FooService, {PARENT_CALLS_CONFIG_KEY: 1})
    service = FooService()

    # Trim stack
    many_ids = [str(i) for i in xrange(100)]
    context = context_cls(container,
                          service,
                          DummyProvider("long"),
                          data={'call_id_stack': many_ids})
    assert context.call_id_stack == ['99', 'baz.long.0']
Exemple #5
0
def test_header_decoder():

    headers = {
        "testprefix.foo": "FOO",
        "testprefix.bar": "BAR",
        "testprefix.baz": "BAZ",
        "bogusprefix.foo": "XXX",
        "testprefix.call_id_stack": ["a", "b", "c"],
    }

    decoder = HeaderDecoder()
    with patch.object(decoder, "header_prefix", new="testprefix"):

        worker_ctx_cls = worker_context_factory("foo", "bar", "call_id_stack")
        message = Mock(headers=headers)

        res = decoder.unpack_message_headers(worker_ctx_cls, message)
        assert res == {"foo": "FOO", "bar": "BAR", "call_id_stack": ["a", "b", "c"]}
Exemple #6
0
def test_header_encoder(empty_config):

    context_data = {
        "foo": "FOO",
        "bar": "BAR",
        "baz": "BAZ",
        # unserialisable, shouldn't be included in the processed headers
        "none": None,
    }

    encoder = HeaderEncoder()
    with patch.object(encoder, "header_prefix", new="testprefix"):

        worker_ctx_cls = worker_context_factory("foo", "bar", "xxx")
        worker_ctx = worker_ctx_cls(data=context_data)
        worker_ctx.call_id_stack = ["x"]

        res = encoder.get_message_headers(worker_ctx)
        assert res == {"testprefix.foo": "FOO", "testprefix.bar": "BAR", "testprefix.call_id_stack": ["x"]}
Exemple #7
0
def test_header_encoder(empty_config):

    context_data = {
        'foo': 'FOO',
        'bar': 'BAR',
        'baz': 'BAZ',
        # unserialisable, shouldn't be included in the processed headers
        'none': None,
    }

    encoder = HeaderEncoder()
    with patch.object(encoder, 'header_prefix', new="testprefix"):

        worker_ctx_cls = worker_context_factory('foo', 'bar', 'xxx')
        worker_ctx = worker_ctx_cls(data=context_data)
        worker_ctx.call_id_stack = ['x']

        res = encoder.get_message_headers(worker_ctx)
        assert res == {'testprefix.foo': 'FOO', 'testprefix.bar': 'BAR',
                       'testprefix.call_id_stack': ['x']}
Exemple #8
0
def test_header_decoder():

    headers = {
        'testprefix.foo': 'FOO',
        'testprefix.bar': 'BAR',
        'testprefix.baz': 'BAZ',
        'bogusprefix.foo': 'XXX',
        'testprefix.call_id_stack': ['a', 'b', 'c'],
    }

    decoder = HeaderDecoder()
    with patch.object(decoder, 'header_prefix', new="testprefix"):

        worker_ctx_cls = worker_context_factory("foo", "bar", "call_id_stack")
        message = Mock(headers=headers)

        res = decoder.unpack_message_headers(worker_ctx_cls, message)
        assert res == {
            'foo': 'FOO',
            'bar': 'BAR',
            'call_id_stack': ['a', 'b', 'c'],
        }
Exemple #9
0
def test_header_decoder():

    headers = {
        'testprefix.foo': 'FOO',
        'testprefix.bar': 'BAR',
        'testprefix.baz': 'BAZ',
        'bogusprefix.foo': 'XXX',
        'testprefix.call_id_stack': ['a', 'b', 'c'],
    }

    decoder = HeaderDecoder()
    with patch.object(decoder, 'header_prefix', new="testprefix"):

        worker_ctx_cls = worker_context_factory("foo", "bar", "call_id_stack")
        message = Mock(headers=headers)

        res = decoder.unpack_message_headers(worker_ctx_cls, message)
        assert res == {
            'foo': 'FOO',
            'bar': 'BAR',
            'call_id_stack': ['a', 'b', 'c'],
        }