4
4
import pytest
5
5
from django .utils import timezone
6
6
7
- from sentry import buffer
8
7
from sentry .eventstore .models import GroupEvent
9
8
from sentry .eventstream .base import GroupState
10
9
from sentry .grouping .grouptype import ErrorGroupType
11
10
from sentry .models .activity import Activity
12
11
from sentry .models .environment import Environment
13
12
from sentry .testutils .factories import Factories
14
13
from sentry .testutils .helpers .datetime import before_now , freeze_time
14
+ from sentry .testutils .helpers .options import override_options
15
15
from sentry .testutils .helpers .redis import mock_redis_buffer
16
16
from sentry .testutils .pytest .fixtures import django_db_all
17
17
from sentry .types .activity import ActivityType
18
18
from sentry .utils import json
19
+ from sentry .workflow_engine import buffer as workflow_buffer
19
20
from sentry .workflow_engine .models import (
20
21
Action ,
21
22
DataConditionGroup ,
@@ -438,7 +439,7 @@ def test_enqueues_workflow_all_logic_type(self) -> None:
438
439
439
440
process_workflows (self .event_data )
440
441
441
- project_ids = buffer . backend .get_sorted_set (
442
+ project_ids = workflow_buffer . get_backend () .get_sorted_set (
442
443
WORKFLOW_ENGINE_BUFFER_LIST_KEY , 0 , self .buffer_timestamp
443
444
)
444
445
assert project_ids
@@ -469,7 +470,7 @@ def test_enqueues_workflow_any_logic_type(self) -> None:
469
470
470
471
process_workflows (self .event_data )
471
472
472
- project_ids = buffer . backend .get_sorted_set (
473
+ project_ids = workflow_buffer . get_backend () .get_sorted_set (
473
474
WORKFLOW_ENGINE_BUFFER_LIST_KEY , 0 , self .buffer_timestamp
474
475
)
475
476
assert project_ids [0 ][0 ] == self .project .id
@@ -549,7 +550,7 @@ def test_enqueues_with_when_and_if_slow_conditions(self) -> None:
549
550
550
551
process_workflows (self .event_data )
551
552
552
- project_ids = buffer . backend .get_sorted_set (
553
+ project_ids = workflow_buffer . get_backend () .get_sorted_set (
553
554
WORKFLOW_ENGINE_BUFFER_LIST_KEY , 0 , self .buffer_timestamp
554
555
)
555
556
assert project_ids [0 ][0 ] == self .project .id
@@ -576,7 +577,7 @@ def test_enqueues_event_if_meets_fast_conditions(self) -> None:
576
577
577
578
process_workflows (self .event_data )
578
579
579
- project_ids = buffer . backend .get_sorted_set (
580
+ project_ids = workflow_buffer . get_backend () .get_sorted_set (
580
581
WORKFLOW_ENGINE_BUFFER_LIST_KEY , 0 , self .buffer_timestamp
581
582
)
582
583
assert not project_ids
@@ -586,7 +587,7 @@ def test_enqueues_event_if_meets_fast_conditions(self) -> None:
586
587
587
588
process_workflows (self .event_data )
588
589
589
- project_ids = buffer . backend .get_sorted_set (
590
+ project_ids = workflow_buffer . get_backend () .get_sorted_set (
590
591
WORKFLOW_ENGINE_BUFFER_LIST_KEY , 0 , self .buffer_timestamp
591
592
)
592
593
assert project_ids [0 ][0 ] == self .project .id
@@ -736,7 +737,7 @@ def test_enqueues_when_slow_conditions(self):
736
737
737
738
enqueue_workflows (queue_items )
738
739
739
- project_ids = buffer . backend .get_sorted_set (
740
+ project_ids = workflow_buffer . get_backend () .get_sorted_set (
740
741
WORKFLOW_ENGINE_BUFFER_LIST_KEY , 0 , timezone .now ().timestamp ()
741
742
)
742
743
assert project_ids
@@ -774,6 +775,7 @@ def setUp(self) -> None:
774
775
775
776
@patch ("sentry.buffer.backend.push_to_sorted_set" )
776
777
@patch ("sentry.buffer.backend.push_to_hash_bulk" )
778
+ @override_options ({"workflow_engine.buffer.use_new_buffer" : False })
777
779
def test_enqueue_workflows__adds_to_workflow_engine_buffer (
778
780
self , mock_push_to_hash_bulk , mock_push_to_sorted_set
779
781
):
@@ -795,8 +797,33 @@ def test_enqueue_workflows__adds_to_workflow_engine_buffer(
795
797
value = [self .group_event .project_id ],
796
798
)
797
799
800
+ @patch ("sentry.workflow_engine.buffer._backend.push_to_sorted_set" )
801
+ @patch ("sentry.workflow_engine.buffer._backend.push_to_hash_bulk" )
802
+ @override_options ({"workflow_engine.buffer.use_new_buffer" : True })
803
+ def test_enqueue_workflows__adds_to_workflow_engine_buffer_new_buffer (
804
+ self , mock_push_to_hash_bulk , mock_push_to_sorted_set
805
+ ):
806
+ enqueue_workflows (
807
+ {
808
+ self .workflow : DelayedWorkflowItem (
809
+ self .workflow ,
810
+ self .group_event ,
811
+ self .workflow .when_condition_group_id ,
812
+ [self .slow_workflow_filter_group .id ],
813
+ [self .workflow_filter_group .id ],
814
+ timestamp = timezone .now (),
815
+ )
816
+ }
817
+ )
818
+
819
+ mock_push_to_sorted_set .assert_called_once_with (
820
+ key = WORKFLOW_ENGINE_BUFFER_LIST_KEY ,
821
+ value = [self .group_event .project_id ],
822
+ )
823
+
798
824
@patch ("sentry.buffer.backend.push_to_sorted_set" )
799
825
@patch ("sentry.buffer.backend.push_to_hash_bulk" )
826
+ @override_options ({"workflow_engine.buffer.use_new_buffer" : False })
800
827
def test_enqueue_workflow__adds_to_workflow_engine_set (
801
828
self , mock_push_to_hash_bulk , mock_push_to_sorted_set
802
829
):
0 commit comments