44from django .test import override_settings
55from django .utils import timezone
66
7- from sentry import buffer , tsdb
7+ from sentry import audit_log , buffer , tsdb
88from sentry .buffer .redis import RedisBuffer
99from sentry .issues .grouptype import PerformanceSlowDBQueryGroupType
1010from sentry .models .activity import Activity
1111from sentry .models .apikey import ApiKey
12+ from sentry .models .auditlogentry import AuditLogEntry
1213from sentry .models .environment import Environment
1314from sentry .models .group import Group , GroupStatus
1415from sentry .models .groupassignee import GroupAssignee
2425from sentry .notifications .types import GroupSubscriptionReason
2526from sentry .plugins .base import plugins
2627from sentry .silo import SiloMode
28+ from sentry .tasks .deletion .hybrid_cloud import schedule_hybrid_cloud_foreign_key_jobs
2729from sentry .testutils .cases import APITestCase , SnubaTestCase
2830from sentry .testutils .helpers .datetime import freeze_time
2931from sentry .testutils .helpers .features import with_feature
32+ from sentry .testutils .outbox import outbox_runner
3033from sentry .testutils .silo import assume_test_silo_mode
3134from sentry .testutils .skips import requires_snuba
3235from sentry .types .activity import ActivityType
@@ -274,8 +277,9 @@ def test_count_with_buffer(self):
274277 self .login_as (user = self .user )
275278
276279 redis_buffer = RedisBuffer ()
277- with mock .patch ("sentry.buffer.backend.get" , redis_buffer .get ), mock .patch (
278- "sentry.buffer.backend.incr" , redis_buffer .incr
280+ with (
281+ mock .patch ("sentry.buffer.backend.get" , redis_buffer .get ),
282+ mock .patch ("sentry.buffer.backend.incr" , redis_buffer .incr ),
279283 ):
280284 event = self .store_event (
281285 data = {"message" : "testing" , "fingerprint" : ["group-1" ]}, project_id = self .project .id
@@ -660,7 +664,7 @@ def test_ratelimit(self):
660664
661665
662666class GroupDeleteTest (APITestCase ):
663- def test_delete (self ):
667+ def test_delete_deferred (self ):
664668 self .login_as (user = self .user )
665669
666670 group = self .create_group ()
@@ -679,6 +683,13 @@ def test_delete(self):
679683
680684 Group .objects .filter (id = group .id ).update (status = GroupStatus .UNRESOLVED )
681685
686+ def test_delete_and_tasks_run (self ):
687+ self .login_as (user = self .user )
688+
689+ group = self .create_group ()
690+ hash = "x" * 32
691+ GroupHash .objects .create (project = group .project , hash = hash , group = group )
692+
682693 url = f"/api/0/issues/{ group .id } /"
683694
684695 with self .tasks ():
@@ -689,6 +700,15 @@ def test_delete(self):
689700 # Now we killed everything with fire
690701 assert not Group .objects .filter (id = group .id ).exists ()
691702 assert not GroupHash .objects .filter (group_id = group .id ).exists ()
703+ with self .tasks (), outbox_runner ():
704+ schedule_hybrid_cloud_foreign_key_jobs ()
705+ with assume_test_silo_mode (SiloMode .CONTROL ):
706+ assert (
707+ AuditLogEntry .objects .get (
708+ event = audit_log .get_event_id ("ISSUE_DELETE" ),
709+ ).data ["issue_id" ]
710+ == group .id
711+ )
692712
693713 def test_delete_performance_issue (self ):
694714 """Test that a performance issue cannot be deleted"""
0 commit comments