Skip to content

Commit 3946bf2

Browse files
committed
Add client isolation test and fix init typing
1 parent c8104b8 commit 3946bf2

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

sentry_sdk/integrations/unleash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class UnleashIntegration(Integration):
1919
_unleash_client = None # type: Optional[UnleashClient]
2020

2121
def __init__(self, unleash_client):
22-
# type: (Optional[UnleashClient]) -> None
22+
# type: (UnleashClient) -> None
2323
self.__class__._unleash_client = unleash_client
2424

2525
@staticmethod

tests/integrations/unleash/test_unleash.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,30 @@ async def runner():
254254
}
255255

256256

257+
def test_client_isolation(sentry_init, capture_events, uninstall_integration):
258+
"""
259+
If the integration is tracking a single client, evaluations from other clients should not be
260+
captured.
261+
"""
262+
client = MockUnleashClient()
263+
uninstall_integration(UnleashIntegration)
264+
sentry_init(integrations=[UnleashIntegration(client)]) # type: ignore
265+
266+
other_client = MockUnleashClient()
267+
268+
other_client.is_enabled("hello")
269+
other_client.is_enabled("world")
270+
other_client.is_enabled("other")
271+
other_client.get_variant("no_payload_feature")
272+
other_client.get_variant("json_feature")
273+
274+
events = capture_events()
275+
sentry_sdk.capture_exception(Exception("something wrong!"))
276+
277+
assert len(events) == 1
278+
assert events[0]["contexts"]["flags"] == {"values": []}
279+
280+
257281
def test_wraps_original(sentry_init, uninstall_integration):
258282
client = MockUnleashClient()
259283
mock_is_enabled = mock.Mock(return_value=random() < 0.5)

0 commit comments

Comments
 (0)