Просмотр исходного кода

fix(hc): Fix test silo access (#56879)

These commits both resolve individual cross-silo test failures
(unfortunately not yet enough to mark the cases stable) and move other
failures closer to the source for easier triage.
Matt Duncan 1 год назад
Родитель
Сommit
b31280e2dc

+ 52 - 40
tests/sentry/incidents/endpoints/test_organization_alert_rule_available_action_index.py

@@ -4,8 +4,9 @@ from sentry.incidents.endpoints.organization_alert_rule_available_action_index i
 )
 from sentry.incidents.models import AlertRuleTriggerAction
 from sentry.models import Integration, OrganizationIntegration
+from sentry.silo import SiloMode
 from sentry.testutils.cases import APITestCase
-from sentry.testutils.silo import region_silo_test
+from sentry.testutils.silo import assume_test_silo_mode, region_silo_test
 
 SERVICES = [
     {
@@ -59,17 +60,20 @@ class OrganizationAlertRuleAvailableActionIndexEndpointTest(APITestCase):
         assert data["allowedTargetTypes"] == ["specific"]
 
     def test_build_action_response_opsgenie(self):
-        integration = Integration.objects.create(
-            provider="opsgenie", name="test-app", external_id="test-app", metadata=METADATA
-        )
-        integration.add_organization(self.organization, self.user)
-        org_integration = OrganizationIntegration.objects.get(
-            organization_id=self.organization.id, integration_id=integration.id
-        )
-        org_integration.config = {
-            "team_table": [{"id": "123-id", "team": "cool-team", "integration_key": "1234-5678"}]
-        }
-        org_integration.save()
+        with assume_test_silo_mode(SiloMode.CONTROL):
+            integration = Integration.objects.create(
+                provider="opsgenie", name="test-app", external_id="test-app", metadata=METADATA
+            )
+            integration.add_organization(self.organization, self.user)
+            org_integration = OrganizationIntegration.objects.get(
+                organization_id=self.organization.id, integration_id=integration.id
+            )
+            org_integration.config = {
+                "team_table": [
+                    {"id": "123-id", "team": "cool-team", "integration_key": "1234-5678"}
+                ]
+            }
+            org_integration.save()
         data = build_action_response(
             self.opsgenie, integration=integration, organization=self.organization
         )
@@ -80,17 +84,18 @@ class OrganizationAlertRuleAvailableActionIndexEndpointTest(APITestCase):
 
     def test_build_action_response_pagerduty(self):
         service_name = SERVICES[0]["service_name"]
-        integration = Integration.objects.create(
-            provider="pagerduty",
-            name="Example PagerDuty",
-            external_id="example-pagerduty",
-            metadata={"services": SERVICES},
-        )
-        integration.add_organization(self.organization, self.user)
-        service = integration.organizationintegration_set.first().add_pagerduty_service(
-            service_name=service_name,
-            integration_key=SERVICES[0]["integration_key"],
-        )
+        with assume_test_silo_mode(SiloMode.CONTROL):
+            integration = Integration.objects.create(
+                provider="pagerduty",
+                name="Example PagerDuty",
+                external_id="example-pagerduty",
+                metadata={"services": SERVICES},
+            )
+            integration.add_organization(self.organization, self.user)
+            service = integration.organizationintegration_set.first().add_pagerduty_service(
+                service_name=service_name,
+                integration_key=SERVICES[0]["integration_key"],
+            )
 
         data = build_action_response(
             self.pagerduty, integration=integration, organization=self.organization
@@ -116,8 +121,9 @@ class OrganizationAlertRuleAvailableActionIndexEndpointTest(APITestCase):
         assert response.data == [build_action_response(self.email)]
 
     def test_simple(self):
-        integration = Integration.objects.create(external_id="1", provider="slack")
-        integration.add_organization(self.organization)
+        with assume_test_silo_mode(SiloMode.CONTROL):
+            integration = Integration.objects.create(external_id="1", provider="slack")
+            integration.add_organization(self.organization)
 
         with self.feature("organizations:incidents"):
             response = self.get_success_response(self.organization.slug)
@@ -132,12 +138,15 @@ class OrganizationAlertRuleAvailableActionIndexEndpointTest(APITestCase):
         )
 
     def test_duplicate_integrations(self):
-        integration = Integration.objects.create(external_id="1", provider="slack", name="slack 1")
-        integration.add_organization(self.organization)
-        other_integration = Integration.objects.create(
-            external_id="2", provider="slack", name="slack 2"
-        )
-        other_integration.add_organization(self.organization)
+        with assume_test_silo_mode(SiloMode.CONTROL):
+            integration = Integration.objects.create(
+                external_id="1", provider="slack", name="slack 1"
+            )
+            integration.add_organization(self.organization)
+            other_integration = Integration.objects.create(
+                external_id="2", provider="slack", name="slack 2"
+            )
+            other_integration.add_organization(self.organization)
 
         with self.feature("organizations:incidents"):
             response = self.get_success_response(self.organization.slug)
@@ -188,8 +197,9 @@ class OrganizationAlertRuleAvailableActionIndexEndpointTest(APITestCase):
         )
 
     def test_no_ticket_actions(self):
-        integration = Integration.objects.create(external_id="1", provider="jira")
-        integration.add_organization(self.organization)
+        with assume_test_silo_mode(SiloMode.CONTROL):
+            integration = Integration.objects.create(external_id="1", provider="jira")
+            integration.add_organization(self.organization)
 
         with self.feature(["organizations:incidents", "organizations:integrations-ticket-rules"]):
             response = self.get_success_response(self.organization.slug)
@@ -199,10 +209,11 @@ class OrganizationAlertRuleAvailableActionIndexEndpointTest(APITestCase):
         assert build_action_response(self.email) in response.data
 
     def test_integration_disabled(self):
-        integration = Integration.objects.create(
-            external_id="1", provider="slack", status=ObjectStatus.DISABLED
-        )
-        integration.add_organization(self.organization)
+        with assume_test_silo_mode(SiloMode.CONTROL):
+            integration = Integration.objects.create(
+                external_id="1", provider="slack", status=ObjectStatus.DISABLED
+            )
+            integration.add_organization(self.organization)
 
         with self.feature("organizations:incidents"):
             response = self.get_success_response(self.organization.slug)
@@ -211,9 +222,10 @@ class OrganizationAlertRuleAvailableActionIndexEndpointTest(APITestCase):
         assert build_action_response(self.email) in response.data
 
     def test_org_integration_disabled(self):
-        integration = Integration.objects.create(external_id="1", provider="slack")
-        org_integration = integration.add_organization(self.organization)
-        org_integration.update(status=ObjectStatus.DISABLED)
+        with assume_test_silo_mode(SiloMode.CONTROL):
+            integration = Integration.objects.create(external_id="1", provider="slack")
+            org_integration = integration.add_organization(self.organization)
+            org_integration.update(status=ObjectStatus.DISABLED)
 
         with self.feature("organizations:incidents"):
             response = self.get_success_response(self.organization.slug)

+ 3 - 1
tests/sentry/receivers/test_onboarding.py

@@ -29,9 +29,10 @@ from sentry.signals import (
     plugin_enabled,
     project_created,
 )
+from sentry.silo import SiloMode
 from sentry.testutils.cases import TestCase
 from sentry.testutils.helpers.datetime import before_now, iso_format
-from sentry.testutils.silo import region_silo_test
+from sentry.testutils.silo import assume_test_silo_mode, region_silo_test
 from sentry.testutils.skips import requires_snuba
 from sentry.utils.samples import load_data
 
@@ -40,6 +41,7 @@ pytestmark = [requires_snuba]
 
 @region_silo_test
 class OrganizationOnboardingTaskTest(TestCase):
+    @assume_test_silo_mode(SiloMode.CONTROL)
     def create_integration(self, provider, external_id=9999):
         return Integration.objects.create(
             provider=provider,