From 625969e0dbc226c8f0cebac8bfc5eba374455817 Mon Sep 17 00:00:00 2001 From: Andrew Liu <159852527+aliu39@users.noreply.github.com> Date: Wed, 4 Dec 2024 14:43:40 -0800 Subject: [PATCH] Test flag values for LD and OF threaded/asyncio, not just flag names --- .../launchdarkly/test_launchdarkly.py | 24 ++++++++++++++----- .../openfeature/test_openfeature.py | 24 ++++++++++++++----- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/tests/integrations/launchdarkly/test_launchdarkly.py b/tests/integrations/launchdarkly/test_launchdarkly.py index acbe764104..7be46f91af 100644 --- a/tests/integrations/launchdarkly/test_launchdarkly.py +++ b/tests/integrations/launchdarkly/test_launchdarkly.py @@ -57,7 +57,7 @@ def task(flag_key): # This means the evaluations in each task are captured separately. with sentry_sdk.isolation_scope(): client.variation(flag_key, context, False) - return [f["flag"] for f in sentry_sdk.get_current_scope().flags.get()] + return sentry_sdk.get_current_scope().flags.get() td.update(td.flag("hello").variation_for_all(True)) td.update(td.flag("world").variation_for_all(False)) @@ -67,8 +67,14 @@ def task(flag_key): with cf.ThreadPoolExecutor(max_workers=2) as pool: results = list(pool.map(task, ["world", "other"])) - assert results[0] == ["hello", "world"] - assert results[1] == ["hello", "other"] + assert results[0] == [ + {"flag": "hello", "result": True}, + {"flag": "world", "result": False}, + ] + assert results[1] == [ + {"flag": "hello", "result": True}, + {"flag": "other", "result": False}, + ] def test_launchdarkly_integration_asyncio(sentry_init): @@ -81,7 +87,7 @@ def test_launchdarkly_integration_asyncio(sentry_init): async def task(flag_key): with sentry_sdk.isolation_scope(): client.variation(flag_key, context, False) - return [f["flag"] for f in sentry_sdk.get_current_scope().flags.get()] + return sentry_sdk.get_current_scope().flags.get() async def runner(): return asyncio.gather(task("world"), task("other")) @@ -91,8 +97,14 @@ async def runner(): client.variation("hello", context, False) results = asyncio.run(runner()).result() - assert results[0] == ["hello", "world"] - assert results[1] == ["hello", "other"] + assert results[0] == [ + {"flag": "hello", "result": True}, + {"flag": "world", "result": False}, + ] + assert results[1] == [ + {"flag": "hello", "result": True}, + {"flag": "other", "result": False}, + ] def test_launchdarkly_integration_did_not_enable(monkeypatch): diff --git a/tests/integrations/openfeature/test_openfeature.py b/tests/integrations/openfeature/test_openfeature.py index 24e7857f9a..7219f155a6 100644 --- a/tests/integrations/openfeature/test_openfeature.py +++ b/tests/integrations/openfeature/test_openfeature.py @@ -44,13 +44,19 @@ def task(flag): # Create a new isolation scope for the thread. This means the flags with sentry_sdk.isolation_scope(): client.get_boolean_value(flag, default_value=False) - return [f["flag"] for f in sentry_sdk.get_current_scope().flags.get()] + return sentry_sdk.get_current_scope().flags.get() with cf.ThreadPoolExecutor(max_workers=2) as pool: results = list(pool.map(task, ["world", "other"])) - assert results[0] == ["hello", "world"] - assert results[1] == ["hello", "other"] + assert results[0] == [ + {"flag": "hello", "result": True}, + {"flag": "world", "result": False}, + ] + assert results[1] == [ + {"flag": "hello", "result": True}, + {"flag": "other", "result": False}, + ] def test_openfeature_integration_asyncio(sentry_init): @@ -59,7 +65,7 @@ def test_openfeature_integration_asyncio(sentry_init): async def task(flag): with sentry_sdk.isolation_scope(): client.get_boolean_value(flag, default_value=False) - return [f["flag"] for f in sentry_sdk.get_current_scope().flags.get()] + return sentry_sdk.get_current_scope().flags.get() async def runner(): return asyncio.gather(task("world"), task("other")) @@ -76,5 +82,11 @@ async def runner(): client.get_boolean_value("hello", default_value=False) results = asyncio.run(runner()).result() - assert results[0] == ["hello", "world"] - assert results[1] == ["hello", "other"] + assert results[0] == [ + {"flag": "hello", "result": True}, + {"flag": "world", "result": False}, + ] + assert results[1] == [ + {"flag": "hello", "result": True}, + {"flag": "other", "result": False}, + ]