From 6462963c40c6ebc693243fb2c3a8df4822628f1e Mon Sep 17 00:00:00 2001 From: scott-codecov Date: Tue, 31 Oct 2023 09:53:09 -0400 Subject: [PATCH] fix: Disable early notify comment (#219) --- upload/helpers.py | 47 ++----------------- upload/tests/test_upload.py | 94 ++----------------------------------- 2 files changed, 8 insertions(+), 133 deletions(-) diff --git a/upload/helpers.py b/upload/helpers.py index bcb11e46d1..d00794c896 100644 --- a/upload/helpers.py +++ b/upload/helpers.py @@ -641,54 +641,15 @@ def dispatch_upload_task(task_arguments, repository, redis): commitid = task_arguments.get("commit") - upload_sig = TaskService().upload_signature( + TaskService().upload( repoid=repository.repoid, commitid=commitid, report_code=task_arguments.get("report_code"), - # this prevents the results of the notify task (below) from being - # passed as args to this upload task - immutable=True, + countdown=max( + countdown, int(get_config("setup", "upload_processing_delay") or 0) + ), ) - # we have a CommitNotifications model for recording if a notification - # has been sent for a particular commit but we'd like this early notification - # (below) to only happen once for a PR. Checking the `commentid` isn't strictly - # correct but works for now since the early notify is only for PR comments. - - notified = False - commit = Commit.objects.filter(commitid=commitid).first() - if commit and commit.pullid is not None: - pull = Pull.objects.filter( - repository_id=commit.repository_id, pullid=commit.pullid - ).first() - if pull and pull.commentid: - notified = True - - if notified: - # we've already notified on this commit - just process - # the upload - upload_sig.apply_async( - countdown=max( - countdown, int(get_config("setup", "upload_processing_delay") or 0) - ), - ) - else: - # we have not notified yet - # - # notify early with a "processing" indicator and then - # start processing the upload - TaskService().notify_signature( - repoid=repository.repoid, - commitid=task_arguments.get("commit"), - empty_upload="processing", - ).apply_async( - link=upload_sig.set( - countdown=max( - countdown, int(get_config("setup", "upload_processing_delay") or 0) - ), - ) - ) - def validate_activated_repo(repository): if repository.active and not repository.activated: diff --git a/upload/tests/test_upload.py b/upload/tests/test_upload.py index 81e83aa822..25a34eddb1 100644 --- a/upload/tests/test_upload.py +++ b/upload/tests/test_upload.py @@ -873,44 +873,9 @@ def test_validate_upload_valid_upload_repo_activated(self): assert repo.active == True assert repo.deleted == False - @patch("services.task.TaskService.notify_signature") - @patch("services.task.TaskService.upload_signature") - def test_dispatch_upload_task_signatures( - self, mock_task_service_upload, mock_task_service_notify - ): - repo = G(Repository) - task_arguments = { - "commit": "commit123", - "version": "v4", - "report_code": "local_report", - } - - expected_key = f"uploads/{repo.repoid}/commit123" - - redis = MockRedis( - expected_task_key=expected_key, - expected_task_arguments=task_arguments, - expected_expire_time=86400, - ) - - dispatch_upload_task(task_arguments, repo, redis) - assert mock_task_service_notify.called - mock_task_service_notify.assert_called_with( - repoid=repo.repoid, - commitid=task_arguments.get("commit"), - empty_upload="processing", - ) - assert mock_task_service_upload.called - mock_task_service_upload.assert_called_with( - repoid=repo.repoid, - commitid=task_arguments.get("commit"), - report_code="local_report", - immutable=True, - ) - @freeze_time("2023-01-01T00:00:00") - @patch("celery.canvas.Signature.apply_async") - def test_dispatch_upload_task_apply_async(self, apply_async): + @patch("services.task.TaskService.upload") + def test_dispatch_upload_task(self, upload): repo = G(Repository) task_arguments = { "commit": "commit123", @@ -927,62 +892,11 @@ def test_dispatch_upload_task_apply_async(self, apply_async): ) dispatch_upload_task(task_arguments, repo, redis) - apply_async.assert_called_once_with( - link={ - "task": "app.tasks.upload.Upload", - "args": (), - "kwargs": { - "repoid": repo.repoid, - "commitid": "commit123", - "report_code": "local_report", - "debug": False, - "rebuild": False, - }, - "options": { - "queue": "uploads", - "headers": {"created_timestamp": "2023-01-01T00:00:00"}, - "time_limit": None, - "soft_time_limit": None, - "countdown": 4, - }, - "subtask_type": None, - "immutable": True, - } - ) - - @patch("services.task.TaskService.notify_signature") - @patch("services.task.TaskService.upload_signature") - def test_dispatch_upload_task_already_notified( - self, - mock_task_service_upload, - mock_task_service_notify, - ): - repo = G(Repository) - pull = PullFactory(repository=repo, commentid="something") - commit = CommitFactory(repository=repo, author=repo.author, pullid=pull.pullid) - task_arguments = { - "commit": commit.commitid, - "version": "v4", - "report_code": "local_report", - } - - expected_key = f"uploads/{repo.repoid}/{commit.commitid}" - - redis = MockRedis( - expected_task_key=expected_key, - expected_task_arguments=task_arguments, - expected_expire_time=86400, - ) - - dispatch_upload_task(task_arguments, repo, redis) - - assert not mock_task_service_notify.called - mock_task_service_upload.assert_called_once() - mock_task_service_upload.assert_called_with( + upload.assert_called_once_with( repoid=repo.repoid, commitid=task_arguments.get("commit"), report_code="local_report", - immutable=True, + countdown=4, )