|
@@ -5,7 +5,8 @@ from unittest.mock import call, patch
|
|
|
|
|
|
import pytest
|
|
|
import responses
|
|
|
-from django.test import RequestFactory, override_settings
|
|
|
+from django.conf import settings
|
|
|
+from django.test import RequestFactory
|
|
|
from freezegun import freeze_time
|
|
|
from pytest import raises
|
|
|
from rest_framework import status
|
|
@@ -28,8 +29,9 @@ from sentry.tasks.deliver_from_outbox import enqueue_outbox_jobs
|
|
|
from sentry.testutils import TestCase
|
|
|
from sentry.testutils.factories import Factories
|
|
|
from sentry.testutils.outbox import outbox_runner
|
|
|
+from sentry.testutils.region import override_regions
|
|
|
from sentry.testutils.silo import control_silo_test, exempt_from_silo_limits, region_silo_test
|
|
|
-from sentry.types.region import MONOLITH_REGION_NAME, Region, RegionCategory
|
|
|
+from sentry.types.region import Region, RegionCategory
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True, scope="function")
|
|
@@ -89,7 +91,7 @@ class ControlOutboxTest(TestCase):
|
|
|
org = Factories.create_organization()
|
|
|
|
|
|
org_mapping = OrganizationMapping.objects.get(organization_id=org.id)
|
|
|
- org_mapping.region_name = MONOLITH_REGION_NAME
|
|
|
+ org_mapping.region_name = settings.SENTRY_MONOLITH_REGION
|
|
|
org_mapping.save()
|
|
|
|
|
|
user1 = Factories.create_user()
|
|
@@ -112,14 +114,14 @@ class ControlOutboxTest(TestCase):
|
|
|
|
|
|
for inst in ControlOutbox.for_webhook_update(
|
|
|
webhook_identifier=WebhookProviderIdentifier.SLACK,
|
|
|
- region_names=[MONOLITH_REGION_NAME, "special-slack-region"],
|
|
|
+ region_names=[settings.SENTRY_MONOLITH_REGION, "special-slack-region"],
|
|
|
request=request,
|
|
|
):
|
|
|
inst.save()
|
|
|
|
|
|
for inst in ControlOutbox.for_webhook_update(
|
|
|
webhook_identifier=WebhookProviderIdentifier.GITHUB,
|
|
|
- region_names=[MONOLITH_REGION_NAME, "special-github-region"],
|
|
|
+ region_names=[settings.SENTRY_MONOLITH_REGION, "special-github-region"],
|
|
|
request=request,
|
|
|
):
|
|
|
inst.save()
|
|
@@ -129,17 +131,17 @@ class ControlOutboxTest(TestCase):
|
|
|
for row in ControlOutbox.find_scheduled_shards()
|
|
|
}
|
|
|
assert shards == {
|
|
|
- (OutboxScope.USER_SCOPE.value, user1.id, MONOLITH_REGION_NAME),
|
|
|
- (OutboxScope.USER_SCOPE.value, user2.id, MONOLITH_REGION_NAME),
|
|
|
+ (OutboxScope.USER_SCOPE.value, user1.id, settings.SENTRY_MONOLITH_REGION),
|
|
|
+ (OutboxScope.USER_SCOPE.value, user2.id, settings.SENTRY_MONOLITH_REGION),
|
|
|
(
|
|
|
OutboxScope.WEBHOOK_SCOPE.value,
|
|
|
WebhookProviderIdentifier.SLACK,
|
|
|
- MONOLITH_REGION_NAME,
|
|
|
+ settings.SENTRY_MONOLITH_REGION,
|
|
|
),
|
|
|
(
|
|
|
OutboxScope.WEBHOOK_SCOPE.value,
|
|
|
WebhookProviderIdentifier.GITHUB,
|
|
|
- MONOLITH_REGION_NAME,
|
|
|
+ settings.SENTRY_MONOLITH_REGION,
|
|
|
),
|
|
|
(
|
|
|
OutboxScope.WEBHOOK_SCOPE.value,
|
|
@@ -187,51 +189,51 @@ class ControlOutboxTest(TestCase):
|
|
|
assert outbox.payload["body"] == '{"installation": {"id": "github:1"}}'
|
|
|
|
|
|
@responses.activate
|
|
|
- @override_settings(SENTRY_REGION_CONFIG=region_config)
|
|
|
def test_drains_successful_success(self):
|
|
|
- mock_response = responses.add(
|
|
|
- self.webhook_request.method,
|
|
|
- f"{self.region.address}{self.webhook_request.path}",
|
|
|
- status=status.HTTP_200_OK,
|
|
|
- )
|
|
|
- expected_request_count = 1 if SiloMode.get_current_mode() == SiloMode.CONTROL else 0
|
|
|
- [outbox] = ControlOutbox.for_webhook_update(
|
|
|
- webhook_identifier=WebhookProviderIdentifier.GITHUB,
|
|
|
- region_names=[self.region.name],
|
|
|
- request=self.webhook_request,
|
|
|
- )
|
|
|
- outbox.save()
|
|
|
+ with override_regions(self.region_config):
|
|
|
+ mock_response = responses.add(
|
|
|
+ self.webhook_request.method,
|
|
|
+ f"{self.region.address}{self.webhook_request.path}",
|
|
|
+ status=status.HTTP_200_OK,
|
|
|
+ )
|
|
|
+ expected_request_count = 1 if SiloMode.get_current_mode() == SiloMode.CONTROL else 0
|
|
|
+ [outbox] = ControlOutbox.for_webhook_update(
|
|
|
+ webhook_identifier=WebhookProviderIdentifier.GITHUB,
|
|
|
+ region_names=[self.region.name],
|
|
|
+ request=self.webhook_request,
|
|
|
+ )
|
|
|
+ outbox.save()
|
|
|
|
|
|
- assert ControlOutbox.objects.filter(id=outbox.id).exists()
|
|
|
- outbox.drain_shard()
|
|
|
- assert mock_response.call_count == expected_request_count
|
|
|
- assert not ControlOutbox.objects.filter(id=outbox.id).exists()
|
|
|
+ assert ControlOutbox.objects.filter(id=outbox.id).exists()
|
|
|
+ outbox.drain_shard()
|
|
|
+ assert mock_response.call_count == expected_request_count
|
|
|
+ assert not ControlOutbox.objects.filter(id=outbox.id).exists()
|
|
|
|
|
|
@responses.activate
|
|
|
- @override_settings(SENTRY_REGION_CONFIG=region_config)
|
|
|
def test_drains_webhook_failure(self):
|
|
|
- mock_response = responses.add(
|
|
|
- self.webhook_request.method,
|
|
|
- f"{self.region.address}{self.webhook_request.path}",
|
|
|
- status=status.HTTP_502_BAD_GATEWAY,
|
|
|
- )
|
|
|
- [outbox] = ControlOutbox.for_webhook_update(
|
|
|
- webhook_identifier=WebhookProviderIdentifier.GITHUB,
|
|
|
- region_names=[self.region.name],
|
|
|
- request=self.webhook_request,
|
|
|
- )
|
|
|
- outbox.save()
|
|
|
+ with override_regions(self.region_config):
|
|
|
+ mock_response = responses.add(
|
|
|
+ self.webhook_request.method,
|
|
|
+ f"{self.region.address}{self.webhook_request.path}",
|
|
|
+ status=status.HTTP_502_BAD_GATEWAY,
|
|
|
+ )
|
|
|
+ [outbox] = ControlOutbox.for_webhook_update(
|
|
|
+ webhook_identifier=WebhookProviderIdentifier.GITHUB,
|
|
|
+ region_names=[self.region.name],
|
|
|
+ request=self.webhook_request,
|
|
|
+ )
|
|
|
+ outbox.save()
|
|
|
|
|
|
- assert ControlOutbox.objects.filter(id=outbox.id).exists()
|
|
|
- if SiloMode.get_current_mode() == SiloMode.CONTROL:
|
|
|
- with raises(ApiError):
|
|
|
- outbox.drain_shard()
|
|
|
- assert mock_response.call_count == 1
|
|
|
assert ControlOutbox.objects.filter(id=outbox.id).exists()
|
|
|
- else:
|
|
|
- outbox.drain_shard()
|
|
|
- assert mock_response.call_count == 0
|
|
|
- assert not ControlOutbox.objects.filter(id=outbox.id).exists()
|
|
|
+ if SiloMode.get_current_mode() == SiloMode.CONTROL:
|
|
|
+ with raises(ApiError):
|
|
|
+ outbox.drain_shard()
|
|
|
+ assert mock_response.call_count == 1
|
|
|
+ assert ControlOutbox.objects.filter(id=outbox.id).exists()
|
|
|
+ else:
|
|
|
+ outbox.drain_shard()
|
|
|
+ assert mock_response.call_count == 0
|
|
|
+ assert not ControlOutbox.objects.filter(id=outbox.id).exists()
|
|
|
|
|
|
|
|
|
@region_silo_test(stable=True)
|