Esempio n. 1
0
    assert c.throw(MyException) == "foobar"

    # finish consumption of the coroutine if necessary
    for _ in c:
        pass


@pytest.mark.parametrize(
    "trace",
    [
        function_trace(name="simple_gen"),
        external_trace(library="lib", url="http://foo.com"),
        database_trace("select * from foo"),
        datastore_trace("lib", "foo", "bar"),
        message_trace("lib", "op", "typ", "name"),
        memcache_trace("cmd"),
    ],
)
def test_coroutine_functions_outside_of_transaction(trace):
    @trace
    def coro():
        for _ in range(2):
            yield "foo"

    assert [_ for _ in coro()] == ["foo", "foo"]


@validate_transaction_metrics(
    "test_catching_generator_exit_causes_runtime_error",
    background_task=True,
    scoped_metrics=[("Function/coro", 1)],
    next(c)

    assert c.throw(MyException) == 'foobar'

    # finish consumption of the coroutine if necessary
    for _ in c:
        pass


@pytest.mark.parametrize('trace', [
    function_trace(name='simple_gen'),
    external_trace(library='lib', url='http://foo.com'),
    database_trace('select * from foo'),
    datastore_trace('lib', 'foo', 'bar'),
    message_trace('lib', 'op', 'typ', 'name'),
    memcache_trace('cmd'),
])
def test_coroutine_functions_outside_of_transaction(trace):
    @trace
    def coro():
        for _ in range(2):
            yield 'foo'

    assert [_ for _ in coro()] == ['foo', 'foo']


@validate_transaction_metrics(
    'test_catching_generator_exit_causes_runtime_error',
    background_task=True,
    scoped_metrics=[('Function/coro', 1)],
    rollup_metrics=[('Function/coro', 1)])