|
| 1 | +from sentry.testutils.cases import TestMigrations |
| 2 | +from sentry.workflow_engine.models import DetectorWorkflow |
| 3 | + |
| 4 | + |
| 5 | +class DropRedundantErrorDetectorWorkflowsTest(TestMigrations): |
| 6 | + migrate_from = "0111_add_workflowfirehistory_date_added_index" |
| 7 | + migrate_to = "0112_drop_redundant_error_detector_workflows" |
| 8 | + app = "workflow_engine" |
| 9 | + |
| 10 | + def setup_initial_state(self) -> None: |
| 11 | + self.org = self.create_organization(name="test-org") |
| 12 | + self.project1 = self.create_project(organization=self.org) |
| 13 | + self.project2 = self.create_project(organization=self.org) |
| 14 | + |
| 15 | + # === Scenario 1: Should DELETE === |
| 16 | + # Error detector workflow with matching issue_stream workflow on same workflow |
| 17 | + self.error_detector_1 = self.create_detector(project=self.project1, type="error") |
| 18 | + self.issue_stream_detector_1 = self.create_detector( |
| 19 | + project=self.project1, type="issue_stream" |
| 20 | + ) |
| 21 | + self.workflow_1 = self.create_workflow(organization=self.org) |
| 22 | + self.dw_error_should_delete = self.create_detector_workflow( |
| 23 | + detector=self.error_detector_1, workflow=self.workflow_1 |
| 24 | + ) |
| 25 | + self.dw_issue_stream_keep = self.create_detector_workflow( |
| 26 | + detector=self.issue_stream_detector_1, workflow=self.workflow_1 |
| 27 | + ) |
| 28 | + |
| 29 | + # === Scenario 2: Should NOT DELETE === |
| 30 | + # Error detector with no matching issue_stream on same workflow |
| 31 | + self.error_detector_2 = self.create_detector(project=self.project1, type="error") |
| 32 | + self.workflow_2 = self.create_workflow(organization=self.org) |
| 33 | + self.dw_error_no_match = self.create_detector_workflow( |
| 34 | + detector=self.error_detector_2, workflow=self.workflow_2 |
| 35 | + ) |
| 36 | + |
| 37 | + # === Scenario 3: Issue_stream detector only === |
| 38 | + self.issue_stream_detector_2 = self.create_detector( |
| 39 | + project=self.project1, type="issue_stream" |
| 40 | + ) |
| 41 | + self.workflow_3 = self.create_workflow(organization=self.org) |
| 42 | + self.dw_issue_stream_only = self.create_detector_workflow( |
| 43 | + detector=self.issue_stream_detector_2, workflow=self.workflow_3 |
| 44 | + ) |
| 45 | + |
| 46 | + # === Scenario 4: Cross-project isolation === |
| 47 | + # Project 2 has error detector only (no issue_stream) |
| 48 | + self.error_detector_p2 = self.create_detector(project=self.project2, type="error") |
| 49 | + self.workflow_p2 = self.create_workflow(organization=self.org) |
| 50 | + self.dw_error_project2 = self.create_detector_workflow( |
| 51 | + detector=self.error_detector_p2, workflow=self.workflow_p2 |
| 52 | + ) |
| 53 | + |
| 54 | + def test_deletes_error_workflow_with_matching_issue_stream(self) -> None: |
| 55 | + assert not DetectorWorkflow.objects.filter(id=self.dw_error_should_delete.id).exists() |
| 56 | + |
| 57 | + def test_preserves_issue_stream_workflow_when_error_deleted(self) -> None: |
| 58 | + assert DetectorWorkflow.objects.filter(id=self.dw_issue_stream_keep.id).exists() |
| 59 | + |
| 60 | + def test_preserves_error_workflow_without_matching_issue_stream(self) -> None: |
| 61 | + assert DetectorWorkflow.objects.filter(id=self.dw_error_no_match.id).exists() |
| 62 | + |
| 63 | + def test_preserves_issue_stream_only_workflow(self) -> None: |
| 64 | + assert DetectorWorkflow.objects.filter(id=self.dw_issue_stream_only.id).exists() |
| 65 | + |
| 66 | + def test_preserves_cross_project_error_workflow_without_issue_stream(self) -> None: |
| 67 | + assert DetectorWorkflow.objects.filter(id=self.dw_error_project2.id).exists() |
| 68 | + |
| 69 | + def test_total_count_after_migration(self) -> None: |
| 70 | + assert DetectorWorkflow.objects.count() == 4 |
0 commit comments