2222
2323
2424class ProcessDelayedAlertConditionsTest (TestCase , APITestCase , BaseEventFrequencyPercentTest ):
25- def create_event (self , project_id , timestamp , fingerprint , environment = None ) -> Event :
25+ def create_event (
26+ self , project_id , timestamp , fingerprint , environment = None , user : bool = True
27+ ) -> Event :
2628 data = {
2729 "timestamp" : iso_format (timestamp ),
2830 "stacktrace" : copy .deepcopy (DEFAULT_EVENT_DATA ["stacktrace" ]),
@@ -70,7 +72,7 @@ def setUp(self):
7072 self .event_frequency_condition3 = self .create_event_frequency_condition (
7173 interval = "1h" , value = 1
7274 )
73- user_frequency_condition = self .create_event_frequency_condition (
75+ self . user_frequency_condition = self .create_event_frequency_condition (
7476 interval = "1m" ,
7577 id = "EventUniqueUserFrequencyCondition" ,
7678 )
@@ -91,7 +93,7 @@ def setUp(self):
9193 assert self .group1
9294
9395 self .rule2 = self .create_project_rule (
94- project = self .project , condition_match = [user_frequency_condition ]
96+ project = self .project , condition_match = [self . user_frequency_condition ]
9597 )
9698 self .event2 = self .create_event (self .project , self .now , "group-2" , self .environment .name )
9799 self .create_event (self .project , self .now , "group-2" , self .environment .name )
@@ -266,3 +268,45 @@ def test_apply_delayed_two_rules_one_fires(self):
266268 rules = apply_delayed (self .project .id )
267269 assert self .rule1 in rules
268270 assert no_fire_rule not in rules
271+
272+ def test_apply_delayed_action_match_all (self ):
273+ """
274+ Test that a rule with multiple conditions and an action match of 'all' is scheduled to fire
275+ """
276+ two_conditions_match_all_rule = self .create_project_rule (
277+ project = self .project ,
278+ condition_match = [self .event_frequency_condition , self .user_frequency_condition ],
279+ environment_id = self .environment .id ,
280+ )
281+ event5 = self .create_event (self .project .id , self .now , "group-5" , self .environment .name )
282+ self .create_event (self .project .id , self .now , "group-5" , self .environment .name )
283+ group5 = event5 .group
284+ assert group5
285+ event6 = self .create_event (
286+ self .project .id , self .now , "group-6" , self .environment .name , user = False
287+ )
288+ self .create_event (self .project .id , self .now , "group-5" , self .environment .name , user = False )
289+ group6 = event6 .group
290+ assert group6
291+ assert self .group1
292+ assert self .group2
293+ condition_wont_pass_rule = self .create_project_rule (
294+ project = self .project ,
295+ condition_match = [self .create_event_frequency_condition (value = 100 )],
296+ environment_id = self .environment .id ,
297+ )
298+
299+ self .push_to_hash (
300+ self .project .id , two_conditions_match_all_rule .id , group5 .id , event5 .event_id
301+ )
302+
303+ with patch ("sentry.buffer.backend.get_hash" , self .redis_buffer .get_hash ):
304+ rules = apply_delayed (self .project .id )
305+ assert self .rule1 in rules
306+ assert self .group1 .id in rules [self .rule1 ]
307+ assert self .rule2 in rules
308+ assert self .group2 .id in rules [self .rule2 ]
309+ assert two_conditions_match_all_rule in rules
310+ assert group5 .id in rules [two_conditions_match_all_rule ]
311+ assert group6 .id not in rules [two_conditions_match_all_rule ]
312+ assert condition_wont_pass_rule not in rules
0 commit comments