예제 #1
0
async def test_client_failure():
    from elasticapm.contrib.asyncio import Client
    from elasticapm.transport.base import TransportException

    client = Client(
        server_url="http://error",
        service_name="service_name",
        secret_token="secret",
        transport_class=".".join((__name__, MockTransport.__name__)),
    )
    client.send(client.config.server_url, foo="bar")
    tasks = asyncio.Task.all_tasks()
    task = next(t for t in tasks if t is not asyncio.Task.current_task())
    with pytest.raises(TransportException):
        await task
    assert client.state.status == 0
예제 #2
0
async def test_client_success():
    from elasticapm.contrib.asyncio import Client

    client = Client(
        server_url="http://localhost",
        service_name="service_name",
        secret_token="secret",
        transport_class=".".join((__name__, MockTransport.__name__)),
    )
    client.send(client.config.server_url, foo="bar")
    tasks = asyncio.Task.all_tasks()
    task = next(t for t in tasks if t is not asyncio.Task.current_task())
    await task
    assert client.state.status == 1
    transport = client._get_transport(urlparse("http://localhost"))
    assert transport.data == client.encode({"foo": "bar"})
예제 #3
0
async def test_client_success():
    from elasticapm.contrib.asyncio import Client

    client = Client(
        server_url='http://localhost',
        service_name='service_name',
        secret_token='secret',
        transport_class='.'.join((__name__, MockTransport.__name__)),
    )
    client.send(client.config.server_url, foo='bar')
    tasks = asyncio.Task.all_tasks()
    task = next(t for t in tasks if t is not asyncio.Task.current_task())
    await task
    assert client.state.status == 1
    transport = client._get_transport(urlparse('http://localhost'))
    assert transport.data == client.encode({'foo': 'bar'})
async def test_client_failure():
    from elasticapm.contrib.asyncio import Client
    from elasticapm.transport.base import TransportException

    client = Client(
        servers=['http://error'],
        app_name='app_name',
        secret_token='secret',
        async_mode=False,
        transport_class='.'.join(
            (__name__, MockTransport.__name__)),
    )
    client.send(foo='bar')
    tasks = asyncio.Task.all_tasks()
    task = next(t for t in tasks if t is not asyncio.Task.current_task())
    with pytest.raises(TransportException):
        await task
    assert client.state.status == 0
예제 #5
0
async def test_client_failure_stdlib_exception(mocker):
    from elasticapm.contrib.asyncio import Client
    from elasticapm.transport.base import TransportException

    client = Client(
        server_url="http://elastic.co",
        service_name="service_name",
        secret_token="secret",
        async_mode=False,
        transport_class="elasticapm.transport.asyncio.AsyncioHTTPTransport",
    )
    mock_client = mocker.Mock()
    mock_client.post = mocker.Mock(side_effect=RuntimeError("oops"))
    transport = client._get_transport(urlparse("http://elastic.co"))
    transport.client = mock_client
    client.send(client.config.server_url, foo="bar")
    tasks = asyncio.Task.all_tasks()
    task = next(t for t in tasks if t is not asyncio.Task.current_task())
    with pytest.raises(TransportException):
        await task
    assert client.state.status == 0
async def test_client_failure_stdlib_exception(mocker):
    from elasticapm.contrib.asyncio import Client
    from elasticapm.transport.base import TransportException

    client = Client(
        servers=['http://elastic.co'],
        app_name='app_name',
        secret_token='secret',
        async_mode=False,
        transport_class='elasticapm.transport.asyncio.AsyncioHTTPTransport',
    )
    mock_client = mocker.Mock()
    mock_client.post = mocker.Mock(side_effect=RuntimeError('oops'))
    transport = client._get_transport(urlparse('http://elastic.co'))
    transport.client = mock_client
    client.send(foo='bar')
    tasks = asyncio.Task.all_tasks()
    task = next(t for t in tasks if t is not asyncio.Task.current_task())
    with pytest.raises(TransportException):
        await task
    assert client.state.status == 0