Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 959d16d

Browse files
fix: update test results finisher to split out old impl (#1182)
1 parent bceb54d commit 959d16d

2 files changed

Lines changed: 36 additions & 15 deletions

File tree

services/test_results.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from dataclasses import dataclass
33
from hashlib import sha256
4-
from typing import Generic, Sequence, TypeVar
4+
from typing import Generic, Sequence, TypedDict, TypeVar
55

66
from shared.django_apps.codecov_auth.models import Plan
77
from shared.plan.constants import TierName
@@ -27,6 +27,13 @@
2727
from services.urls import get_members_url, get_test_analytics_url
2828
from services.yaml import read_yaml_field
2929

30+
31+
class FinisherResult(TypedDict):
32+
notify_attempted: bool
33+
notify_succeeded: bool
34+
queue_notify: bool
35+
36+
3037
log = logging.getLogger(__name__)
3138

3239

tasks/test_results_finisher.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
2-
from dataclasses import dataclass
3-
from typing import Any
2+
from typing import Any, Literal
43

54
from asgiref.sync import async_to_sync
65
from shared.reports.types import UploadType
@@ -9,8 +8,8 @@
98
from sqlalchemy.orm import Session
109

1110
from app import celery_app
12-
from database.enums import FlakeSymptomType, ReportType
13-
from database.models import Commit, Flake, TestResultReportTotals
11+
from database.enums import ReportType
12+
from database.models import Commit, Flake, Repository, TestResultReportTotals
1413
from helpers.checkpoint_logger.flows import TestResultsFlow
1514
from helpers.notifier import NotifierResult
1615
from helpers.string import EscapeEnum, Replacement, StringEscaper, shorten_file_paths
@@ -23,6 +22,7 @@
2322
)
2423
from services.seats import ShouldActivateSeat, determine_seat_activation
2524
from services.test_results import (
25+
FinisherResult,
2626
FlakeInfo,
2727
TACommentInDepthInfo,
2828
TestResultsNotificationFailure,
@@ -46,13 +46,6 @@
4646
]
4747

4848

49-
@dataclass
50-
class FlakeUpdateInfo:
51-
new_flake_ids: list[str]
52-
old_flake_ids: list[str]
53-
newly_calculated_flakes: dict[str, set[FlakeSymptomType]]
54-
55-
5649
class TestResultsFinisherTask(BaseCodecovTask, name=test_results_finisher_task_name):
5750
def run_impl(
5851
self,
@@ -62,11 +55,18 @@ def run_impl(
6255
repoid: int,
6356
commitid: str,
6457
commit_yaml: dict,
58+
impl_type: Literal["old", "new", "both"] = "old",
6559
**kwargs,
6660
):
61+
if impl_type == "both":
62+
impl_type = "old"
63+
6764
repoid = int(repoid)
6865

69-
self.extra_dict: dict[str, Any] = {"commit_yaml": commit_yaml}
66+
self.extra_dict: dict[str, Any] = {
67+
"commit_yaml": commit_yaml,
68+
"impl_type": impl_type,
69+
}
7070
log.info("Starting test results finisher task", extra=self.extra_dict)
7171

7272
lock_manager = LockManager(
@@ -89,6 +89,7 @@ def run_impl(
8989
commitid=commitid,
9090
commit_yaml=UserYaml.from_dict(commit_yaml),
9191
chain_result=chain_result,
92+
impl_type=impl_type,
9293
**kwargs,
9394
)
9495
if finisher_result["queue_notify"]:
@@ -114,8 +115,9 @@ def process_impl_within_lock(
114115
commitid: str,
115116
commit_yaml: UserYaml,
116117
chain_result: bool,
118+
impl_type: Literal["old", "new"],
117119
**kwargs,
118-
):
120+
) -> FinisherResult:
119121
log.info("Running test results finishers", extra=self.extra_dict)
120122
TestResultsFlow.log(TestResultsFlow.TEST_RESULTS_FINISHER_BEGIN)
121123

@@ -125,6 +127,18 @@ def process_impl_within_lock(
125127
assert commit, "commit not found"
126128
repo = commit.repository
127129

130+
return self.old_impl(db_session, repo, commit, chain_result, commit_yaml)
131+
132+
def old_impl(
133+
self,
134+
db_session: Session,
135+
repo: Repository,
136+
commit: Commit,
137+
chain_result: bool,
138+
commit_yaml: UserYaml,
139+
) -> FinisherResult:
140+
repoid = repo.repoid
141+
commitid = commit.commitid
128142
redis_client = get_redis_connection()
129143

130144
if should_do_flaky_detection(repo, commit_yaml):
@@ -348,7 +362,7 @@ def get_flaky_tests(
348362
self,
349363
db_session: Session,
350364
repoid: int,
351-
failures: list[TestResultsNotificationFailure],
365+
failures: list[TestResultsNotificationFailure[str]],
352366
) -> dict[str, FlakeInfo]:
353367
failure_test_ids = [failure.test_id for failure in failures]
354368

0 commit comments

Comments
 (0)