|
19 | 19 | from sentry.models.project import Project |
20 | 20 | from sentry.testutils.cases import TestCase |
21 | 21 | from sentry.testutils.helpers.eventprocessing import save_new_event |
| 22 | +from sentry.testutils.helpers.options import override_options |
22 | 23 | from sentry.testutils.pytest.fixtures import django_db_all |
23 | 24 | from sentry.testutils.silo import assume_test_silo_mode_of |
24 | 25 | from sentry.testutils.skips import requires_snuba |
@@ -239,6 +240,80 @@ def test_no_ops_if_grouping_config_project_option_exists_and_is_current( |
239 | 240 | assert self.project.get_option("sentry:secondary_grouping_config") is None |
240 | 241 | assert self.project.get_option("sentry:secondary_grouping_expiry") == 0 |
241 | 242 |
|
| 243 | + @patch( |
| 244 | + "sentry.event_manager.update_or_set_grouping_config_if_needed", |
| 245 | + wraps=update_or_set_grouping_config_if_needed, |
| 246 | + ) |
| 247 | + def test_no_ops_if_sample_rate_test_fails(self, update_config_spy: MagicMock): |
| 248 | + with ( |
| 249 | + # Ensure our die roll will fall outside the sample rate |
| 250 | + patch("sentry.grouping.ingest.config.random", return_value=0.1121), |
| 251 | + override_options({"grouping.config_transition.config_upgrade_sample_rate": 0.0908}), |
| 252 | + ): |
| 253 | + self.project.update_option("sentry:grouping_config", NO_MSG_PARAM_CONFIG) |
| 254 | + assert self.project.get_option("sentry:grouping_config") == NO_MSG_PARAM_CONFIG |
| 255 | + |
| 256 | + save_new_event({"message": "Dogs are great!"}, self.project) |
| 257 | + |
| 258 | + update_config_spy.assert_called_with(self.project, "ingest") |
| 259 | + |
| 260 | + # After the function has been called, the config hasn't changed and no transition has |
| 261 | + # started |
| 262 | + assert self.project.get_option("sentry:grouping_config") == NO_MSG_PARAM_CONFIG |
| 263 | + assert self.project.get_option("sentry:secondary_grouping_config") is None |
| 264 | + assert self.project.get_option("sentry:secondary_grouping_expiry") == 0 |
| 265 | + |
| 266 | + @patch( |
| 267 | + "sentry.event_manager.update_or_set_grouping_config_if_needed", |
| 268 | + wraps=update_or_set_grouping_config_if_needed, |
| 269 | + ) |
| 270 | + def test_ignores_sample_rate_if_current_config_is_invalid(self, update_config_spy: MagicMock): |
| 271 | + with ( |
| 272 | + # Ensure our die roll will fall outside the sample rate |
| 273 | + patch("sentry.grouping.ingest.config.random", return_value=0.1121), |
| 274 | + override_options({"grouping.config_transition.config_upgrade_sample_rate": 0.0908}), |
| 275 | + ): |
| 276 | + self.project.update_option("sentry:grouping_config", "not_a_real_config") |
| 277 | + assert self.project.get_option("sentry:grouping_config") == "not_a_real_config" |
| 278 | + |
| 279 | + save_new_event({"message": "Dogs are great!"}, self.project) |
| 280 | + |
| 281 | + update_config_spy.assert_called_with(self.project, "ingest") |
| 282 | + |
| 283 | + # The config has been updated, but no transition has started because we can't calculate |
| 284 | + # a secondary hash using a config that doesn't exist |
| 285 | + assert self.project.get_option("sentry:grouping_config") == DEFAULT_GROUPING_CONFIG |
| 286 | + assert self.project.get_option("sentry:secondary_grouping_config") is None |
| 287 | + assert self.project.get_option("sentry:secondary_grouping_expiry") == 0 |
| 288 | + |
| 289 | + @patch( |
| 290 | + "sentry.event_manager.update_or_set_grouping_config_if_needed", |
| 291 | + wraps=update_or_set_grouping_config_if_needed, |
| 292 | + ) |
| 293 | + def test_ignores_sample_rate_if_no_record_exists(self, update_config_spy: MagicMock): |
| 294 | + with ( |
| 295 | + # Ensure our die roll will fall outside the sample rate |
| 296 | + patch("sentry.grouping.ingest.config.random", return_value=0.1121), |
| 297 | + override_options({"grouping.config_transition.config_upgrade_sample_rate": 0.0908}), |
| 298 | + ): |
| 299 | + assert self.project.get_option("sentry:grouping_config") == DEFAULT_GROUPING_CONFIG |
| 300 | + assert not ProjectOption.objects.filter( |
| 301 | + project_id=self.project.id, key="sentry:grouping_config" |
| 302 | + ).exists() |
| 303 | + |
| 304 | + save_new_event({"message": "Dogs are great!"}, self.project) |
| 305 | + |
| 306 | + update_config_spy.assert_called_with(self.project, "ingest") |
| 307 | + |
| 308 | + # The config hasn't been updated, but now the project has its own record. No transition |
| 309 | + # has started because the config was already up to date. |
| 310 | + assert self.project.get_option("sentry:grouping_config") == DEFAULT_GROUPING_CONFIG |
| 311 | + assert ProjectOption.objects.filter( |
| 312 | + project_id=self.project.id, key="sentry:grouping_config" |
| 313 | + ).exists() |
| 314 | + assert self.project.get_option("sentry:secondary_grouping_config") is None |
| 315 | + assert self.project.get_option("sentry:secondary_grouping_expiry") == 0 |
| 316 | + |
242 | 317 |
|
243 | 318 | class PlaceholderTitleTest(TestCase): |
244 | 319 | """ |
|
0 commit comments