Skip to content

Commit

Permalink
Test flag values for LD and OF threaded/asyncio, not just flag names
Browse files Browse the repository at this point in the history
  • Loading branch information
aliu39 committed Dec 4, 2024
1 parent 3652ce3 commit 625969e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
24 changes: 18 additions & 6 deletions tests/integrations/launchdarkly/test_launchdarkly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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):
Expand All @@ -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"))
Expand All @@ -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):
Expand Down
24 changes: 18 additions & 6 deletions tests/integrations/openfeature/test_openfeature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"))
Expand All @@ -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},
]

0 comments on commit 625969e

Please sign in to comment.