@@ -2117,39 +2117,51 @@ def test_throws_when_matches_discarded_hash(self) -> None:
21172117 )
21182118 GroupHash .objects .filter (group = group ).update (group = None , group_tombstone_id = tombstone .id )
21192119
2120- manager = EventManager (
2121- make_event (message = "foo" , event_id = "b" * 32 , fingerprint = ["a" * 32 ]),
2122- project = self .project ,
2123- )
2124- manager .normalize ()
2120+ from sentry .utils .outcomes import track_outcome
21252121
21262122 a1 = CachedAttachment (name = "a1" , data = b"hello" )
21272123 a2 = CachedAttachment (name = "a2" , data = b"world" )
21282124
2129- cache_key = cache_key_for_event (manager .get_data ())
2130- attachment_cache .set (cache_key , attachments = [a1 , a2 ])
2125+ for i , event_id in enumerate (["b" * 32 , "c" * 32 ]):
2126+ manager = EventManager (
2127+ make_event (message = "foo" , event_id = event_id , fingerprint = ["a" * 32 ]),
2128+ project = self .project ,
2129+ )
2130+ manager .normalize ()
2131+ discarded_event = Event (
2132+ project_id = self .project .id , event_id = event_id , data = manager .get_data ()
2133+ )
21312134
2132- from sentry .utils .outcomes import track_outcome
2135+ cache_key = cache_key_for_event (manager .get_data ())
2136+ attachment_cache .set (cache_key , attachments = [a1 , a2 ])
21332137
2134- mock_track_outcome = mock .Mock (wraps = track_outcome )
2135- with mock .patch ("sentry.event_manager.track_outcome" , mock_track_outcome ):
2136- with self .feature ("organizations:event-attachments" ):
2137- with self .tasks ():
2138- with pytest .raises (HashDiscarded ):
2139- manager .save (self .project .id , cache_key = cache_key , has_attachments = True )
2138+ mock_track_outcome = mock .Mock (wraps = track_outcome )
2139+ with (
2140+ mock .patch ("sentry.event_manager.track_outcome" , mock_track_outcome ),
2141+ self .feature ("organizations:event-attachments" ),
2142+ self .feature ("organizations:grouptombstones-hit-counter" ),
2143+ self .tasks (),
2144+ pytest .raises (HashDiscarded ),
2145+ ):
2146+ manager .save (self .project .id , cache_key = cache_key , has_attachments = True )
21402147
2141- assert mock_track_outcome .call_count == 3
2148+ assert mock_track_outcome .call_count == 3
21422149
2143- for o in mock_track_outcome .mock_calls :
2144- assert o .kwargs ["outcome" ] == Outcome .FILTERED
2145- assert o .kwargs ["reason" ] == FilterStatKeys .DISCARDED_HASH
2150+ event_outcome = mock_track_outcome .mock_calls [0 ].kwargs
2151+ assert event_outcome ["outcome" ] == Outcome .FILTERED
2152+ assert event_outcome ["reason" ] == FilterStatKeys .DISCARDED_HASH
2153+ assert event_outcome ["category" ] == DataCategory .ERROR
2154+ assert event_outcome ["event_id" ] == event_id
21462155
2147- o = mock_track_outcome .mock_calls [0 ]
2148- assert o .kwargs ["category" ] == DataCategory .ERROR
2156+ for call in mock_track_outcome .mock_calls [1 :]:
2157+ attachment_outcome = call .kwargs
2158+ assert attachment_outcome ["category" ] == DataCategory .ATTACHMENT
2159+ assert attachment_outcome ["quantity" ] == 5
21492160
2150- for o in mock_track_outcome .mock_calls [1 :]:
2151- assert o .kwargs ["category" ] == DataCategory .ATTACHMENT
2152- assert o .kwargs ["quantity" ] == 5
2161+ expected_times_seen = 1 + i
2162+ tombstone .refresh_from_db ()
2163+ assert tombstone .times_seen == expected_times_seen
2164+ assert tombstone .last_seen == discarded_event .datetime
21532165
21542166 def test_honors_crash_report_limit (self ) -> None :
21552167 from sentry .utils .outcomes import track_outcome
0 commit comments