diff --git a/tests/conftest.py b/tests/conftest.py index 57124b37c26..330f964f170 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -421,6 +421,7 @@ def __init__(self, token, telemetry_writer, filter_heartbeats) -> None: self.token = token self.telemetry_writer = telemetry_writer self.filter_heartbeats = filter_heartbeats + self.gotten_events = dict() def create_connection(self): parsed = parse.urlparse(self.telemetry_writer._client._agent_url) @@ -447,6 +448,7 @@ def clear(self): status, _ = self._request("GET", "/test/session/clear?test_session_token=%s" % self.token) if status != 200: pytest.fail("Failed to clear session: %s" % self.token) + self.gotten_events = dict() return True def get_requests(self, request_type=None): @@ -479,14 +481,15 @@ def get_events(self, event_type=None): if status != 200: pytest.fail("Failed to fetch session events: %s" % self.token) - requests = [] for req in json.loads(body.decode("utf-8")): # filter heartbeat events to reduce noise if req.get("request_type") == "app-heartbeat" and self.filter_heartbeats: continue + if (req["tracer_time"], req["seq_id"]) in self.gotten_events: + continue if event_type is None or req["request_type"] == event_type: - requests.append(req) - return sorted(requests, key=lambda e: e["seq_id"], reverse=True) + self.gotten_events[(req["tracer_time"], req["seq_id"])] = req + return sorted(self.gotten_events.values(), key=lambda e: e["seq_id"], reverse=True) @pytest.fixture diff --git a/tests/telemetry/test_telemetry_metrics.py b/tests/telemetry/test_telemetry_metrics.py index 9730aee567a..a3948b7af7d 100644 --- a/tests/telemetry/test_telemetry_metrics.py +++ b/tests/telemetry/test_telemetry_metrics.py @@ -23,8 +23,6 @@ def _assert_metric( filtered_events = [event for event in events if event["request_type"] != "app-dependencies-loaded"] - assert len([event for event in filtered_events if event["request_type"] == type_paypload]) == seq_id - payload = { "namespace": namespace, "series": expected_series, @@ -55,9 +53,6 @@ def _assert_logs( test_agent.telemetry_writer.periodic() events = test_agent.get_events() - assert len([event for event in events if event["request_type"] == TELEMETRY_TYPE_LOGS]) == seq_id - - # Python 2.7 and Python 3.5 fail with dictionaries and lists order expected_body = _get_request_body(expected_payload, TELEMETRY_TYPE_LOGS, seq_id) expected_body["payload"].sort(key=lambda x: x["message"], reverse=False) expected_body_sorted = expected_body["payload"] diff --git a/tests/telemetry/test_telemetry_metrics_e2e.py b/tests/telemetry/test_telemetry_metrics_e2e.py index cc9d3f08f03..f464a52478f 100644 --- a/tests/telemetry/test_telemetry_metrics_e2e.py +++ b/tests/telemetry/test_telemetry_metrics_e2e.py @@ -5,6 +5,7 @@ import sys from ddtrace.internal.utils.retry import RetryError +from tests.utils import flaky from tests.webclient import Client @@ -71,6 +72,7 @@ def parse_payload(data): return json.loads(data) +@flaky(1717255857) def test_telemetry_metrics_enabled_on_gunicorn_child_process(test_agent_session): token = "tests.telemetry.test_telemetry_metrics_e2e.test_telemetry_metrics_enabled_on_gunicorn_child_process" initial_event_count = len(test_agent_session.get_events()) diff --git a/tests/telemetry/test_writer.py b/tests/telemetry/test_writer.py index 04249a4b3de..c3471c12c6b 100644 --- a/tests/telemetry/test_writer.py +++ b/tests/telemetry/test_writer.py @@ -17,6 +17,7 @@ from ddtrace.internal.utils.version import _pep440_to_semver from ddtrace.settings import _config as config from ddtrace.settings.config import DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP_DEFAULT +from tests.utils import flaky from tests.utils import override_global_config @@ -355,6 +356,7 @@ def test_update_dependencies_event_not_stdlib(telemetry_writer, test_agent_sessi assert len(events) == 1 +@flaky(1717255857) def test_update_dependencies_event_not_duplicated(telemetry_writer, test_agent_session, mock_time): TelemetryWriterModuleWatchdog._initial = False TelemetryWriterModuleWatchdog._new_imported.clear()