11import copy
2+ import time
23from collections .abc import Mapping
34from datetime import UTC , datetime , timedelta
45from random import choice
@@ -1519,10 +1520,9 @@ def test_backfill_seer_grouping_records_enable_ingestion(
15191520 assert self .project .get_option ("sentry:similarity_backfill_completed" ) is not None
15201521
15211522 @with_feature ("projects:similarity-embeddings-backfill" )
1522- @patch ("sentry.tasks.embeddings_grouping.utils.logger" )
15231523 @patch ("sentry.tasks.embeddings_grouping.utils.post_bulk_grouping_records" )
15241524 def test_backfill_seer_grouping_records_no_enable_ingestion (
1525- self , mock_post_bulk_grouping_records , mock_logger
1525+ self , mock_post_bulk_grouping_records
15261526 ):
15271527 """
15281528 Test that when the enable_ingestion flag is False, the project option is not set.
@@ -1540,3 +1540,121 @@ def test_backfill_seer_grouping_records_no_enable_ingestion(
15401540 }
15411541
15421542 assert self .project .get_option ("sentry:similarity_backfill_completed" ) is None
1543+
1544+ @with_feature ("projects:similarity-embeddings-backfill" )
1545+ @patch ("sentry.tasks.embeddings_grouping.backfill_seer_grouping_records_for_project.logger" )
1546+ def test_backfill_seer_grouping_records_skip_project_already_processed (self , mock_logger ):
1547+ """
1548+ Test that projects that have a backfill completed project option are skipped when passed
1549+ the skip_processed_projects flag.
1550+ """
1551+ self .project .update_option ("sentry:similarity_backfill_completed" , int (time .time ()))
1552+ with TaskRunner ():
1553+ backfill_seer_grouping_records_for_project (
1554+ self .project .id , None , skip_processed_projects = True
1555+ )
1556+
1557+ expected_call_args_list = [
1558+ call (
1559+ "backfill_seer_grouping_records" ,
1560+ extra = {
1561+ "current_project_id" : self .project .id ,
1562+ "last_processed_group_id" : None ,
1563+ "cohort" : None ,
1564+ "last_processed_project_index" : None ,
1565+ "only_delete" : False ,
1566+ },
1567+ ),
1568+ call (
1569+ "backfill_seer_grouping_records.project_skipped" ,
1570+ extra = {
1571+ "project_id" : self .project .id ,
1572+ "project_already_processed" : True ,
1573+ "project_manually_skipped" : None ,
1574+ },
1575+ ),
1576+ call ("backfill finished, no cohort" , extra = {"project_id" : self .project .id }),
1577+ ]
1578+ assert mock_logger .info .call_args_list == expected_call_args_list
1579+
1580+ @with_feature ("projects:similarity-embeddings-backfill" )
1581+ @patch ("sentry.tasks.embeddings_grouping.backfill_seer_grouping_records_for_project.logger" )
1582+ @patch ("sentry.tasks.embeddings_grouping.utils.post_bulk_grouping_records" )
1583+ def test_backfill_seer_grouping_records_reprocess_project_already_processed (
1584+ self , mock_post_bulk_grouping_records , mock_logger
1585+ ):
1586+ """
1587+ Test that projects that have a backfill completed project option are not skipped when not
1588+ passed the skip_processed_projects flag.
1589+ """
1590+ mock_post_bulk_grouping_records .return_value = {"success" : True , "groups_with_neighbor" : {}}
1591+ self .project .update_option ("sentry:similarity_backfill_completed" , int (time .time ()))
1592+ with TaskRunner ():
1593+ backfill_seer_grouping_records_for_project (self .project .id , None )
1594+
1595+ last_group_id = sorted (
1596+ [group .id for group in Group .objects .filter (project_id = self .project .id )]
1597+ )[0 ]
1598+ expected_call_args_list = [
1599+ call (
1600+ "backfill_seer_grouping_records" ,
1601+ extra = {
1602+ "current_project_id" : self .project .id ,
1603+ "last_processed_group_id" : None ,
1604+ "cohort" : None ,
1605+ "last_processed_project_index" : None ,
1606+ "only_delete" : False ,
1607+ },
1608+ ),
1609+ call ("about to call next backfill" , extra = {"project_id" : self .project .id }),
1610+ call (
1611+ "calling next backfill task" ,
1612+ extra = {"project_id" : self .project .id , "last_processed_group_id" : last_group_id },
1613+ ),
1614+ call (
1615+ "backfill_seer_grouping_records" ,
1616+ extra = {
1617+ "current_project_id" : self .project .id ,
1618+ "last_processed_group_id" : last_group_id ,
1619+ "cohort" : None ,
1620+ "last_processed_project_index" : 0 ,
1621+ "only_delete" : False ,
1622+ },
1623+ ),
1624+ call ("backfill finished, no cohort" , extra = {"project_id" : self .project .id }),
1625+ ]
1626+ assert mock_logger .info .call_args_list == expected_call_args_list
1627+
1628+ @with_feature ("projects:similarity-embeddings-backfill" )
1629+ @patch ("sentry.tasks.embeddings_grouping.backfill_seer_grouping_records_for_project.logger" )
1630+ def test_backfill_seer_grouping_records_manually_skip_project (self , mock_logger ):
1631+ """
1632+ Test that project ids that are included in the skip_project_ids field are skipped.
1633+ """
1634+ with TaskRunner ():
1635+ backfill_seer_grouping_records_for_project (
1636+ self .project .id , None , skip_project_ids = [self .project .id ]
1637+ )
1638+
1639+ expected_call_args_list = [
1640+ call (
1641+ "backfill_seer_grouping_records" ,
1642+ extra = {
1643+ "current_project_id" : self .project .id ,
1644+ "last_processed_group_id" : None ,
1645+ "cohort" : None ,
1646+ "last_processed_project_index" : None ,
1647+ "only_delete" : False ,
1648+ },
1649+ ),
1650+ call (
1651+ "backfill_seer_grouping_records.project_skipped" ,
1652+ extra = {
1653+ "project_id" : self .project .id ,
1654+ "project_already_processed" : False ,
1655+ "project_manually_skipped" : True ,
1656+ },
1657+ ),
1658+ call ("backfill finished, no cohort" , extra = {"project_id" : self .project .id }),
1659+ ]
1660+ assert mock_logger .info .call_args_list == expected_call_args_list
0 commit comments