11import logging
2- from dataclasses import dataclass
3- from typing import Any
2+ from typing import Any , Literal
43
54from asgiref .sync import async_to_sync
65from shared .reports .types import UploadType
98from sqlalchemy .orm import Session
109
1110from 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
1413from helpers .checkpoint_logger .flows import TestResultsFlow
1514from helpers .notifier import NotifierResult
1615from helpers .string import EscapeEnum , Replacement , StringEscaper , shorten_file_paths
2322)
2423from services .seats import ShouldActivateSeat , determine_seat_activation
2524from services .test_results import (
25+ FinisherResult ,
2626 FlakeInfo ,
2727 TACommentInDepthInfo ,
2828 TestResultsNotificationFailure ,
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-
5649class 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