55from random import choice
66from string import ascii_uppercase
77from typing import Any
8- from unittest .mock import call , patch
8+ from unittest .mock import ANY , call , patch
99
1010import pytest
1111from django .test import override_settings
@@ -241,15 +241,15 @@ def test_lookup_group_data_stacktrace_bulk_exceptions(
241241 mock_get_multi .side_effect = exception
242242 with pytest .raises (Exception ):
243243 lookup_group_data_stacktrace_bulk (self .project , rows )
244- mock_logger .exception .assert_called_with (
245- "tasks.backfill_seer_grouping_records.bulk_event_lookup_exception" ,
246- extra = {
247- "organization_id" : self .project .organization .id ,
248- "project_id" : self .project .id ,
249- "group_data " : json . dumps ( rows ) ,
250- "error" : exception .message ,
251- },
252- )
244+ mock_logger .exception .assert_called_with (
245+ "tasks.backfill_seer_grouping_records.bulk_event_lookup_exception" ,
246+ extra = {
247+ "organization_id" : self .project .organization .id ,
248+ "project_id" : self .project .id ,
249+ "node_keys " : ANY ,
250+ "error" : exception .message ,
251+ },
252+ )
253253
254254 def test_lookup_group_data_stacktrace_bulk_not_stacktrace_grouping (self ):
255255 """
@@ -446,7 +446,7 @@ def test_get_data_from_snuba(self):
446446 assert group_id in group_ids_results
447447
448448 @patch ("sentry.tasks.embeddings_grouping.utils.logger" )
449- @patch ("sentry.utils.snuba .bulk_snuba_queries" )
449+ @patch ("sentry.tasks.embeddings_grouping.utils .bulk_snuba_queries" )
450450 def test_get_data_from_snuba_exception (self , mock_bulk_snuba_queries , mock_logger ):
451451 mock_bulk_snuba_queries .side_effect = RateLimitExceeded
452452
@@ -455,14 +455,14 @@ def test_get_data_from_snuba_exception(self, mock_bulk_snuba_queries, mock_logge
455455 }
456456 with pytest .raises (Exception ):
457457 get_data_from_snuba (self .project , group_ids_last_seen )
458- mock_logger .exception .assert_called_with (
459- "tasks.backfill_seer_grouping_records.snuba_query_exception" ,
460- extra = {
461- "organization_id" : self .project .organization .id ,
462- "project_id" : self .project .id ,
463- "error" : "Snuba Rate Limit Exceeded" ,
464- },
465- )
458+ mock_logger .exception .assert_called_with (
459+ "tasks.backfill_seer_grouping_records.snuba_query_exception" ,
460+ extra = {
461+ "organization_id" : self .project .organization .id ,
462+ "project_id" : self .project .id ,
463+ "error" : "Snuba Rate Limit Exceeded" ,
464+ },
465+ )
466466
467467 @with_feature ("projects:similarity-embeddings-backfill" )
468468 @patch ("sentry.tasks.embeddings_grouping.utils.post_bulk_grouping_records" )
@@ -1541,6 +1541,29 @@ def test_backfill_seer_grouping_records_no_enable_ingestion(
15411541
15421542 assert self .project .get_option ("sentry:similarity_backfill_completed" ) is None
15431543
1544+ @with_feature ("projects:similarity-embeddings-backfill" )
1545+ @patch ("time.sleep" , return_value = None )
1546+ @patch ("sentry.tasks.embeddings_grouping.utils.logger" )
1547+ @patch ("sentry.tasks.embeddings_grouping.utils.post_bulk_grouping_records" )
1548+ def test_backfill_seer_grouping_records_seer_exception (
1549+ self , mock_post_bulk_grouping_records , mock_logger , mock_sleep
1550+ ):
1551+ """
1552+ Test log after seer exception and retries.
1553+ """
1554+ exception = ServiceUnavailable (message = "Service Unavailable" )
1555+ mock_post_bulk_grouping_records .side_effect = exception
1556+ with pytest .raises (Exception ), TaskRunner ():
1557+ backfill_seer_grouping_records_for_project (self .project .id , None )
1558+
1559+ mock_logger .exception .assert_called_with (
1560+ "tasks.backfill_seer_grouping_records.seer_exception_after_retries" ,
1561+ extra = {
1562+ "project_id" : self .project .id ,
1563+ "error" : exception ,
1564+ },
1565+ )
1566+
15441567 @with_feature ("projects:similarity-embeddings-backfill" )
15451568 @patch ("sentry.tasks.embeddings_grouping.backfill_seer_grouping_records_for_project.logger" )
15461569 def test_backfill_seer_grouping_records_skip_project_already_processed (self , mock_logger ):
0 commit comments