Skip to content

flaky tornado test on pypy / ubuntu #4070

@xrmx

Description

@xrmx
______ TestTornadoMetricsInstrumentation.test_metrics_concurrent_requests ______

self = <tests.test_metrics_instrumentation.TestTornadoMetricsInstrumentation testMethod=test_metrics_concurrent_requests>

    @tornado.testing.gen_test
    async def test_metrics_concurrent_requests(self):
        """
        Test that metrics can handle concurrent requests and calculate in an async-safe way.
        """
        req1 = self.http_client.fetch(self.get_url("/slow?duration=1.0"))
        req2 = self.http_client.fetch(self.get_url("/async"))
        await asyncio.gather(req1, req2)
    
        metrics = self.get_sorted_metrics()
        self.assertEqual(len(metrics), 7)
    
        client_duration = metrics[0]
        server_duration = metrics[4]
        self.assertEqual(client_duration.name, "http.client.duration")
        self.assertEqual(server_duration.name, "http.server.duration")
    
        # Calculating duration requires tracking state via `_HANDLER_STATE_KEY`, so we want to make sure
        # duration is calculated properly per request, and doesn't affect concurrent requests.
        req1_client_duration_data_point = next(
            dp
            for dp in client_duration.data.data_points
            if "/slow" in dp.attributes.get("http.url")
        )
        req1_server_duration_data_point = next(
            dp
            for dp in server_duration.data.data_points
            if "/slow" in dp.attributes.get("http.target")
        )
        req2_client_duration_data_point = next(
            dp
            for dp in client_duration.data.data_points
            if "/async" in dp.attributes.get("http.url")
        )
        req2_server_duration_data_point = next(
            dp
            for dp in server_duration.data.data_points
            if "/async" in dp.attributes.get("http.target")
        )
    
        # Server and client durations should be similar (adjusting for msecs vs secs)
        self.assertAlmostEqual(
            abs(
                req1_server_duration_data_point.sum / 1000.0
                - req1_client_duration_data_point.sum
            ),
            0.0,
            delta=0.01,
        )
>       self.assertAlmostEqual(
            abs(
                req2_server_duration_data_point.sum / 1000.0
                - req2_client_duration_data_point.sum
            ),
            0.0,
            delta=0.01,
        )
E       AssertionError: 0.012130353927612305 != 0.0 within 0.01 delta (0.012130353927612305 difference)

instrumentation/opentelemetry-instrumentation-tornado/tests/test_metrics_instrumentation.py:220: AssertionError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions