From 3ed06b2c7303087a0dda6bf69a2e5a83f9becc12 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Thu, 7 Dec 2023 13:59:16 +0100 Subject: [PATCH 1/4] Python 2 dict comparison is pickie about dict key ordering --- tests/test_metrics.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 3f8b6049d8..cfd6135988 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -723,7 +723,7 @@ def should_summarize_metric(key, tags): "d:foo@second": [ { "tags": { - "a": "b", + "b": "c", "environment": "not-fun-env", "release": "fun-release@1.0.0", "transaction": "/foo", @@ -735,7 +735,7 @@ def should_summarize_metric(key, tags): }, { "tags": { - "b": "c", + "a": "b", "environment": "not-fun-env", "release": "fun-release@1.0.0", "transaction": "/foo", From f36d355f1c4c43bafa686d877a4a1e55484173fd Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Thu, 7 Dec 2023 14:17:07 +0100 Subject: [PATCH 2/4] Trying with DictionaryContaining --- tests/test_metrics.py | 56 ++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/tests/test_metrics.py b/tests/test_metrics.py index cfd6135988..6096f5dcbc 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -680,7 +680,7 @@ def test_metrics_summary_disabled(sentry_init, capture_envelopes): assert "_metrics_summary" not in t["spans"][0] -def test_metrics_summary_filtered(sentry_init, capture_envelopes): +def test_metrics_summary_filtered(sentry_init, capture_envelopes, DictionaryContaining): def should_summarize_metric(key, tags): return key == "foo" @@ -719,34 +719,36 @@ def should_summarize_metric(key, tags): # Measurement Attachment t = transaction.items[0].get_transaction_event()["_metrics_summary"] - assert t == { - "d:foo@second": [ - { - "tags": { - "b": "c", - "environment": "not-fun-env", - "release": "fun-release@1.0.0", - "transaction": "/foo", + assert t == DictionaryContaining( + { + "d:foo@second": [ + { + "tags": { + "b": "c", + "environment": "not-fun-env", + "release": "fun-release@1.0.0", + "transaction": "/foo", + }, + "min": 1.0, + "max": 1.0, + "count": 1, + "sum": 1.0, }, - "min": 1.0, - "max": 1.0, - "count": 1, - "sum": 1.0, - }, - { - "tags": { - "a": "b", - "environment": "not-fun-env", - "release": "fun-release@1.0.0", - "transaction": "/foo", + { + "tags": { + "a": "b", + "environment": "not-fun-env", + "release": "fun-release@1.0.0", + "transaction": "/foo", + }, + "min": 1.0, + "max": 1.0, + "count": 1, + "sum": 1.0, }, - "min": 1.0, - "max": 1.0, - "count": 1, - "sum": 1.0, - }, - ] - } + ] + } + ) def test_tag_normalization(sentry_init, capture_envelopes): From 84f17add4f344623077be138c13a1a39137edf6d Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Thu, 7 Dec 2023 14:21:46 +0100 Subject: [PATCH 3/4] Linting --- tests/test_metrics.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 6096f5dcbc..8a5c927f49 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -680,7 +680,11 @@ def test_metrics_summary_disabled(sentry_init, capture_envelopes): assert "_metrics_summary" not in t["spans"][0] -def test_metrics_summary_filtered(sentry_init, capture_envelopes, DictionaryContaining): +def test_metrics_summary_filtered( + sentry_init, + capture_envelopes, + DictionaryContaining, # noqa: N803 +): def should_summarize_metric(key, tags): return key == "foo" From 5b3480cd0ef982f7f8dee24ff9dd5e70f507ef01 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Thu, 7 Dec 2023 14:55:21 +0100 Subject: [PATCH 4/4] Made test non-flaky between different python versions --- tests/test_metrics.py | 65 +++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 8a5c927f49..98afea6f02 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -680,11 +680,7 @@ def test_metrics_summary_disabled(sentry_init, capture_envelopes): assert "_metrics_summary" not in t["spans"][0] -def test_metrics_summary_filtered( - sentry_init, - capture_envelopes, - DictionaryContaining, # noqa: N803 -): +def test_metrics_summary_filtered(sentry_init, capture_envelopes): def should_summarize_metric(key, tags): return key == "foo" @@ -704,8 +700,8 @@ def should_summarize_metric(key, tags): with start_transaction( op="stuff", name="/foo", source=TRANSACTION_SOURCE_ROUTE ) as transaction: - metrics.timing("foo", value=1.0, tags={"a": "b"}, timestamp=ts) - metrics.timing("foo", value=1.0, tags={"b": "c"}, timestamp=ts) + metrics.timing("foo", value=3.0, tags={"a": "b"}, timestamp=ts) + metrics.timing("foo", value=2.0, tags={"b": "c"}, timestamp=ts) metrics.timing("bar", value=1.0, tags={"a": "b"}, timestamp=ts) Hub.current.flush() @@ -723,36 +719,31 @@ def should_summarize_metric(key, tags): # Measurement Attachment t = transaction.items[0].get_transaction_event()["_metrics_summary"] - assert t == DictionaryContaining( - { - "d:foo@second": [ - { - "tags": { - "b": "c", - "environment": "not-fun-env", - "release": "fun-release@1.0.0", - "transaction": "/foo", - }, - "min": 1.0, - "max": 1.0, - "count": 1, - "sum": 1.0, - }, - { - "tags": { - "a": "b", - "environment": "not-fun-env", - "release": "fun-release@1.0.0", - "transaction": "/foo", - }, - "min": 1.0, - "max": 1.0, - "count": 1, - "sum": 1.0, - }, - ] - } - ) + assert len(t["d:foo@second"]) == 2 + assert { + "tags": { + "a": "b", + "environment": "not-fun-env", + "release": "fun-release@1.0.0", + "transaction": "/foo", + }, + "min": 3.0, + "max": 3.0, + "count": 1, + "sum": 3.0, + } in t["d:foo@second"] + assert { + "tags": { + "b": "c", + "environment": "not-fun-env", + "release": "fun-release@1.0.0", + "transaction": "/foo", + }, + "min": 2.0, + "max": 2.0, + "count": 1, + "sum": 2.0, + } in t["d:foo@second"] def test_tag_normalization(sentry_init, capture_envelopes):