Пример #1
0
def test_traces_match_query(http_helper, exporter):
    response = yield http_helper.get(url_string(query=QUERY),
                                     headers=GRAPHQL_HEADER)
    assert response.code == 200
    assert 'data' in response_json(response)

    # OpenCensus is quite ready for Python3+Tornado yet
    if six.PY3:
        return

    spans = exporter.spans

    assert spans[0][0].name == 'author'
    assert spans[0][0].parent_span_id == spans[6][0].span_id
    assert spans[1][0].name == 'aBoolean'
    assert spans[1][0].parent_span_id == spans[6][0].span_id
    assert spans[2][0].name == 'author.name'
    assert spans[2][0].parent_span_id == spans[6][0].span_id
    assert spans[3][0].name == 'author.posts'
    assert spans[3][0].parent_span_id == spans[6][0].span_id
    assert spans[4][0].name == 'author.posts.0.id'
    assert spans[4][0].parent_span_id == spans[6][0].span_id
    assert spans[5][0].name == 'author.posts.1.id'
    assert spans[5][0].parent_span_id == spans[6][0].span_id

    assert spans[6][0].name == 'gql[b5c7307ba564]'
    assert spans[6][0].parent_span_id is None
    assert spans[6][0].attributes.get(
        'signature',
        None) == default_engine_reporting_signature(parse(QUERY), '')
def test_traces_match_query(http_helper, exporter):
    response = yield http_helper.get(url_string(query=QUERY),
                                     headers=GRAPHQL_HEADER)
    assert response.code == 200
    assert "data" in response_json(response)

    parent = exporter.spans.pop()[0]

    assert parent.name == "gql[b5c7307ba564]"
    assert parent.parent_span_id is None
    assert parent.attributes.get("signature",
                                 None) == default_engine_reporting_signature(
                                     parse(QUERY), "")

    spans = [span for span_list in exporter.spans for span in span_list]

    expected = [
        "gql_parsing",
        "gql_validation",
        "author",
        "aBoolean",
        "author.name",
        "author.posts",
        "author.posts.0.id",
        "author.posts.1.id",
    ]

    for span, exp in zip(spans, expected):
        assert span.name == exp
        assert span.parent_span_id == parent.span_id
Пример #3
0
def test_extensions_are_called_in_order(http_helper):
    response = yield http_helper.get(url_string(
        query='query helloWho($who: String){ test(who: $who) }',
        variables=json.dumps({'who': "Dolly"})),
                                     headers=GRAPHQL_HEADER)

    assert response.code == 200
    assert response_json(response) == {'data': {'test': "Hello Dolly"}}

    assert [
        'request', 'parsing', 'validation', 'execution', 'resolve_field',
        'response'
    ] == STARTED
    assert ['parsing', 'validation', 'resolve_field', 'execution',
            'request'] == ENDED
Пример #4
0
def test_can_send_report_to_engine(http_helper):
    response = yield http_helper.get(url_string(query=QUERY), headers=GRAPHQL_HEADER)

    report = _deserialize(agent.data[0])

    assert report.header.hostname == SERVICE_HEADER_DEFAULTS.get('hostname')
    assert report.header.agent_version == SERVICE_HEADER_DEFAULTS.get('agentVersion')
    assert report.header.runtime_version == SERVICE_HEADER_DEFAULTS.get('runtimeVersion')
    assert report.header.uname == SERVICE_HEADER_DEFAULTS.get('uname')

    assert len(report.traces_per_query) == 1
    key = next(iter(report.traces_per_query))
    query_key = '# -\n' + default_engine_reporting_signature(parse(QUERY), '')
    assert query_key == key
    assert report.traces_per_query[query_key].trace.pop()

    assert response.code == 200
    assert 'data' in response_json(response)
def test_can_send_report_to_engine(http_helper):
    response = yield http_helper.get(url_string(query=QUERY),
                                     headers=GRAPHQL_HEADER)
    assert response.code == 200
    assert 'data' in response_json(response)

    assert len(traces) == 1
    operation_name, document_ast, query_string, trace = traces[0]

    assert QUERY == query_string
    assert parse(QUERY) == document_ast
    assert '' == operation_name

    trace_json = MessageToJson(trace, sort_keys=True)
    trace_json = re.sub(r'"([0-9]+)"', '"-1"', trace_json)
    trace_json = re.sub(r'"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d+Z"',
                        '"2019-09-21T19:37:09.908919Z"', trace_json)

    e = expected
    if six.PY3:
        e = re.sub(r'\s+\n', '\n', expected)
    assert e == trace_json
def test_extensions_are_called_in_order(http_helper):
    response = yield http_helper.get(
        url_string(
            query="query helloWho($who: String){ test(who: $who) }",
            variables=json.dumps({"who": "Dolly"}),
        ),
        headers=GRAPHQL_HEADER,
    )

    assert response.code == 200
    assert response_json(response) == {"data": {"test": "Hello Dolly"}}

    assert [
        "request",
        "parsing",
        "validation",
        "execution",
        "resolve_field",
        "response",
    ] == STARTED
    assert ["parsing", "validation", "execution", "resolve_field",
            "request"] == ENDED
def test_can_send_report_to_engine(http_helper):
    response = yield http_helper.get(url_string(query=QUERY),
                                     headers=GRAPHQL_HEADER)
    assert response.code == 200
    assert "data" in response_json(response)