Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions codecov/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@
dsn=SENTRY_DSN,
event_scrubber=EventScrubber(denylist=SENTRY_DENY_LIST),
integrations=[
DjangoIntegration(),
DjangoIntegration(signals_spans=False),
CeleryIntegration(),
RedisIntegration(),
RedisIntegration(cache_prefixes=["cache:"]),
HttpxIntegration(),
],
environment=SENTRY_ENV,
Expand Down
2 changes: 1 addition & 1 deletion codecov/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

ALLOWED_HOSTS = ["localhost"]
CORS_ALLOWED_ORIGINS = ["http://localhost:9000", "http://localhost"]
SHELTER_ENABLED = True
SHELTER_ENABLED = False
SHELTER_PUBSUB_PROJECT_ID = "test-project-id"
SHELTER_PUBSUB_SYNC_REPO_TOPIC_ID = "test-topic-id"

Expand Down
92 changes: 37 additions & 55 deletions codecov_auth/tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,37 @@
from unittest.mock import call

import pytest
from django.test import TestCase
from django.test import TestCase, override_settings
from shared.django_apps.codecov_auth.models import Service
from shared.django_apps.codecov_auth.tests.factories import (
OrganizationLevelTokenFactory,
OwnerFactory,
)

from utils.shelter import ShelterPubsub


@pytest.mark.django_db
def test_shelter_org_token_sync(mocker):
publish = mocker.patch("google.cloud.pubsub_v1.PublisherClient.publish")
publish = mocker.patch("utils.shelter.ShelterPubsub.publish")

# this triggers the publish via Django signals
OrganizationLevelTokenFactory(id=91728376, owner=OwnerFactory(ownerid=111))

publish.assert_has_calls(
[
call(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "owner", "sync": "one", "id": 111}',
),
call(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "org_token", "sync": "one", "id": 91728376}',
),
call({"type": "owner", "sync": "one", "id": 111}),
call({"type": "org_token", "sync": "one", "id": 91728376}),
]
)


@mock.patch("google.cloud.pubsub_v1.PublisherClient.publish")
@mock.patch("utils.shelter.ShelterPubsub.publish")
class TestCodecovAuthSignals(TestCase):
def test_sync_on_create(self, mock_publish):
OwnerFactory(ownerid=12345)
mock_publish.assert_called_once_with(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "owner", "sync": "one", "id": 12345}',
{"type": "owner", "sync": "one", "id": 12345}
)

def test_sync_on_update_upload_token_required_for_public_repos(self, mock_publish):
Expand All @@ -46,14 +41,8 @@ def test_sync_on_update_upload_token_required_for_public_repos(self, mock_publis
owner.save()
mock_publish.assert_has_calls(
[
call(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "owner", "sync": "one", "id": 12345}',
),
call(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "owner", "sync": "one", "id": 12345}',
),
call({"type": "owner", "sync": "one", "id": 12345}),
call({"type": "owner", "sync": "one", "id": 12345}),
]
)

Expand All @@ -63,14 +52,8 @@ def test_sync_on_update_username(self, mock_publish):
owner.save()
mock_publish.assert_has_calls(
[
call(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "owner", "sync": "one", "id": 12345}',
),
call(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "owner", "sync": "one", "id": 12345}',
),
call({"type": "owner", "sync": "one", "id": 12345}),
call({"type": "owner", "sync": "one", "id": 12345}),
]
)

Expand All @@ -80,14 +63,8 @@ def test_sync_on_update_service(self, mock_publish):
owner.save()
mock_publish.assert_has_calls(
[
call(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "owner", "sync": "one", "id": 12345}',
),
call(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "owner", "sync": "one", "id": 12345}',
),
call({"type": "owner", "sync": "one", "id": 12345}),
call({"type": "owner", "sync": "one", "id": 12345}),
]
)

Expand All @@ -96,26 +73,31 @@ def test_no_sync_on_update_other_fields(self, mock_publish):
owner.name = "world"
owner.save()
mock_publish.assert_called_once_with(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "owner", "sync": "one", "id": 12345}',
{"type": "owner", "sync": "one", "id": 12345}
)

@mock.patch("logging.Logger.warning")
def test_sync_error(self, mock_log, mock_publish):
mock_publish.side_effect = Exception("publish error")

OwnerFactory(ownerid=12345)
@mock.patch("logging.Logger.warning")
@mock.patch("google.cloud.pubsub_v1.PublisherClient.publish")
@mock.patch("utils.shelter.ShelterPubsub.get_instance")
@override_settings(SHELTER_ENABLED=True)
@pytest.mark.django_db
def test_sync_error(mock_instance, mock_publish, mock_log):
mock_instance.return_value = ShelterPubsub()
mock_publish.side_effect = Exception("publish error")

# publish is still called, raises an Exception
mock_publish.assert_called_once_with(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "owner", "sync": "one", "id": 12345}',
)
OwnerFactory(ownerid=12345)

mock_log.assert_called_once_with(
"Failed to publish a message",
extra=dict(
data_to_publish={"type": "owner", "sync": "one", "id": 12345},
error=mock_publish.side_effect,
),
)
# publish is still called, raises an Exception
mock_publish.assert_called_once_with(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "owner", "sync": "one", "id": 12345}',
)

mock_log.assert_called_once_with(
"Failed to publish a message",
extra=dict(
data_to_publish={"type": "owner", "sync": "one", "id": 12345},
error=mock_publish.side_effect,
),
)
33 changes: 7 additions & 26 deletions core/tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@pytest.mark.django_db
def test_shelter_repo_sync(mocker):
publish = mocker.patch("google.cloud.pubsub_v1.PublisherClient.publish")
publish = mocker.patch("utils.shelter.ShelterPubsub.publish")

# this triggers the publish via Django signals
repo = RepositoryFactory(
Expand All @@ -17,14 +17,8 @@ def test_shelter_repo_sync(mocker):
# triggers publish on create
publish.assert_has_calls(
[
call(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "owner", "sync": "one", "id": 555}',
),
call(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "repo", "sync": "one", "id": 91728376}',
),
call({"type": "owner", "sync": "one", "id": 555}),
call({"type": "repo", "sync": "one", "id": 91728376}),
]
)

Expand All @@ -35,10 +29,7 @@ def test_shelter_repo_sync(mocker):
assert len(publish_calls) == 3

# triggers publish on update
assert publish_calls[2] == call(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "repo", "sync": "one", "id": 91728376}',
)
assert publish_calls[2] == call({"type": "repo", "sync": "one", "id": 91728376})

# Does not trigger another publish with untracked field
repo.message = "foo"
Expand All @@ -54,14 +45,7 @@ def test_shelter_repo_sync(mocker):
publish_calls = publish.call_args_list
# 1 is for the new owner created
assert len(publish_calls) == 5
publish.assert_has_calls(
[
call(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "owner", "sync": "one", "id": 888}',
),
]
)
publish.assert_has_calls([call({"type": "owner", "sync": "one", "id": 888})])

# Triggers call when private is changed
repo.private = True
Expand All @@ -73,7 +57,7 @@ def test_shelter_repo_sync(mocker):

@pytest.mark.django_db
def test_shelter_commit_sync(mocker):
publish = mocker.patch("google.cloud.pubsub_v1.PublisherClient.publish")
publish = mocker.patch("utils.shelter.ShelterPubsub.publish")

# this triggers the publish via Django signals - has to have this format
owner = OwnerFactory(ownerid=555)
Expand All @@ -90,10 +74,7 @@ def test_shelter_commit_sync(mocker):
assert len(publish_calls) == 3

# triggers publish on update
assert publish_calls[2] == call(
"projects/test-project-id/topics/test-topic-id",
b'{"type": "commit", "sync": "one", "id": 167829367}',
)
assert publish_calls[2] == call({"type": "commit", "sync": "one", "id": 167829367})

commit.branch = "normal-incompatible-branch"
commit.save()
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ dependencies = [
"redis==4.4.4",
"regex==2023.12.25",
"requests==2.32.3",
"sentry-sdk>=2.13.0",
"sentry-sdk[celery]==2.13.0",
"sentry-sdk>=2.25.1",
"sentry-sdk[celery]>=2.25.1",
"shared",
"simplejson==3.17.2",
"starlette==0.40.0",
Expand Down Expand Up @@ -74,4 +74,4 @@ dev-dependencies = [
]

[tool.uv.sources]
shared = { git = "https://github.com/codecov/shared", rev = "ece4366f3bce7fab2216704f85e365fbbe0f147d" }
shared = { git = "https://github.com/codecov/shared", rev = "ae1d4cf84490f0ae41395cda3567fe3db7124be3" }
15 changes: 0 additions & 15 deletions services/task/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
from datetime import datetime, timedelta
from typing import Iterable, List, Optional, Tuple

import celery
from celery import Celery, chain, group, signature
from celery.canvas import Signature
from django.conf import settings
from sentry_sdk import set_tag
from sentry_sdk.integrations.celery import _wrap_apply_async
from shared import celery_config

from core.models import Repository
Expand All @@ -19,17 +15,6 @@

log = logging.getLogger(__name__)

if settings.SENTRY_ENV:
celery.group.apply_async = _wrap_apply_async(celery.group.apply_async)
celery.chunks.apply_async = _wrap_apply_async(celery.chunks.apply_async)
celery.canvas._chain.apply_async = _wrap_apply_async(
celery.canvas._chain.apply_async
)
celery.canvas._chord.apply_async = _wrap_apply_async(
celery.canvas._chord.apply_async
)
Signature.apply_async = _wrap_apply_async(Signature.apply_async)


class TaskService(object):
def _create_signature(self, name, args=None, kwargs=None, immutable=False):
Expand Down
14 changes: 7 additions & 7 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading