Skip to content

Commit c713d79

Browse files
fix(np): random.randint (#105099)
1 parent d267770 commit c713d79

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/sentry/notifications/platform/rollout.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import random
23
from dataclasses import dataclass
34

45
from sentry import features, options
@@ -25,7 +26,7 @@ def should_notify(self, source: NotificationTemplateSource) -> bool:
2526
return False
2627

2728
source_rollout_rate = self.get_rollout_rate(option_key, source)
28-
return (self.organization.id % 100) < 100 * source_rollout_rate
29+
return random.randint(0, 99) < 100 * source_rollout_rate
2930

3031
def has_feature_flag_access(self) -> str | None:
3132
internal_testing = features.has(

tests/sentry/notifications/platform/test_rollout.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import random
2+
13
from sentry.notifications.platform.rollout import NotificationRolloutService
24
from sentry.notifications.platform.templates.types import NotificationTemplateSource
35
from sentry.testutils.cases import TestCase
@@ -9,6 +11,7 @@ class NotificationRolloutServiceTest(TestCase):
911
def setUp(self) -> None:
1012
super().setUp()
1113
self.organization = self.create_organization()
14+
random.seed(0)
1215

1316
def test_no_feature_flags_enabled(self) -> None:
1417
service = NotificationRolloutService(organization=self.organization)
@@ -73,10 +76,7 @@ def test_unknown_option_returns_false(self) -> None:
7376
@with_feature("organizations:notification-platform.internal-testing")
7477
def test_partial_rollout_based_on_org_id(self) -> None:
7578
service = NotificationRolloutService(organization=self.organization)
76-
expected_result = (self.organization.id % 100) < 50
77-
assert (
78-
service.should_notify(NotificationTemplateSource.DATA_EXPORT_SUCCESS) == expected_result
79-
)
79+
assert service.should_notify(NotificationTemplateSource.DATA_EXPORT_SUCCESS)
8080

8181
def test_has_feature_flag_access_returns_none_when_no_flags(self) -> None:
8282
service = NotificationRolloutService(organization=self.organization)
@@ -139,7 +139,5 @@ def test_multiple_sources_different_rates(self) -> None:
139139
service = NotificationRolloutService(organization=self.organization)
140140

141141
assert service.should_notify(NotificationTemplateSource.DATA_EXPORT_SUCCESS)
142-
assert service.should_notify(NotificationTemplateSource.DATA_EXPORT_FAILURE) == (
143-
self.organization.id % 100 < 50
144-
)
142+
assert not service.should_notify(NotificationTemplateSource.DATA_EXPORT_FAILURE)
145143
assert not service.should_notify(NotificationTemplateSource.SLOW_LOAD_METRIC_ALERT)

0 commit comments

Comments
 (0)