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

Commit 2c7bd18

Browse files
feat: new ta tasks (#976)
1 parent 6080307 commit 2c7bd18

25 files changed

Lines changed: 1920 additions & 266 deletions

requirements.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
https://github.com/codecov/test-results-parser/archive/996ecb2aaf7767bf4c2944c75835c1ee1eb2b566.tar.gz#egg=test-results-parser
1+
https://github.com/codecov/test-results-parser/archive/190bbc8a911099749928e13d5fe57f6027ca1e74.tar.gz#egg=test-results-parser
22
https://github.com/codecov/shared/archive/de4b37bc5a736317c6e7c93f9c58e9ae07f8c96b.tar.gz#egg=shared
33
https://github.com/codecov/timestring/archive/d37ceacc5954dff3b5bd2f887936a98a668dda42.tar.gz#egg=timestring
44
asgiref>=3.7.2
@@ -37,6 +37,7 @@ pytest-celery
3737
pytest-cov
3838
pytest-django
3939
pytest-freezegun
40+
pytest-insta
4041
pytest-mock
4142
pytest-sqlalchemy
4243
python-dateutil

requirements.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ pytest==8.1.1
301301
# pytest-cov
302302
# pytest-django
303303
# pytest-freezegun
304+
# pytest-insta
304305
# pytest-mock
305306
# pytest-sqlalchemy
306307
pytest-asyncio==0.14.0
@@ -313,6 +314,8 @@ pytest-django==4.7.0
313314
# via -r requirements.in
314315
pytest-freezegun==0.4.2
315316
# via -r requirements.in
317+
pytest-insta==0.3.0
318+
# via -r requirements.in
316319
pytest-mock==1.13.0
317320
# via -r requirements.in
318321
pytest-sqlalchemy==0.2.1
@@ -402,7 +405,7 @@ statsd==3.3.0
402405
# via -r requirements.in
403406
stripe==11.4.1
404407
# via -r requirements.in
405-
test-results-parser @ https://github.com/codecov/test-results-parser/archive/996ecb2aaf7767bf4c2944c75835c1ee1eb2b566.tar.gz#egg=test-results-parser
408+
test-results-parser @ https://github.com/codecov/test-results-parser/archive/190bbc8a911099749928e13d5fe57f6027ca1e74.tar.gz#egg=test-results-parser
406409
# via -r requirements.in
407410
text-unidecode==1.3
408411
# via faker
@@ -442,6 +445,7 @@ wcwidth==0.2.5
442445
wrapt==1.16.0
443446
# via
444447
# deprecated
448+
# pytest-insta
445449
# vcrpy
446450
yarl==1.9.4
447451
# via vcrpy

rollouts/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@
1212
SHOW_IMPACT_ANALYSIS_DEPRECATION_MSG = Feature(
1313
"show_impact_analysis_deprecation_message"
1414
)
15+
16+
NEW_TA_TASKS = Feature("new_ta_tasks")

services/processing/flake_processing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ def process_flake_for_repo_commit(
2222
):
2323
uploads = ReportSession.objects.filter(
2424
report__report_type=CommitReport.ReportType.TEST_RESULTS.value,
25+
report__commit__repository__repoid=repo_id,
2526
report__commit__commitid=commit_id,
26-
state="processed",
27+
state__in=["processed", "v2_finished"],
2728
).all()
2829

2930
curr_flakes = fetch_curr_flakes(repo_id)

services/test_results.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from database.models import (
1414
Commit,
1515
CommitReport,
16+
Flake,
1617
Repository,
1718
RepositoryFlag,
1819
TestInstance,
@@ -410,3 +411,12 @@ def should_do_flaky_detection(repo: Repository, commit_yaml: UserYaml) -> bool:
410411
)
411412
has_valid_plan_repo_or_owner = not_private_and_free_or_team(repo)
412413
return has_flaky_configured and (feature_enabled or has_valid_plan_repo_or_owner)
414+
415+
416+
def get_flake_set(db_session: Session, repoid: int) -> set[str]:
417+
repo_flakes: list[Flake] = (
418+
db_session.query(Flake.testid)
419+
.filter(Flake.repoid == repoid, Flake.end_date.is_(None))
420+
.all()
421+
)
422+
return {flake.testid for flake in repo_flakes}

ta_storage/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from __future__ import annotations
2+
13
from abc import ABC, abstractmethod
24

3-
from test_results_parser import Testrun
5+
import test_results_parser
46

57
from database.models.reports import Upload
68

@@ -15,6 +17,6 @@ def write_testruns(
1517
branch_name: str,
1618
upload: Upload,
1719
framework: str | None,
18-
testruns: list[Testrun],
20+
testruns: list[test_results_parser.Testrun],
1921
):
2022
pass

ta_storage/bq.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
from __future__ import annotations
2+
13
from datetime import datetime
24
from typing import Literal, TypedDict, cast
35

6+
import test_results_parser
47
from shared.config import get_config
5-
from test_results_parser import Testrun
68

79
import generated_proto.testrun.ta_testrun_pb2 as ta_testrun_pb2
810
from database.models.reports import Upload
@@ -52,7 +54,7 @@ def write_testruns(
5254
branch_name: str,
5355
upload: Upload,
5456
framework: str | None,
55-
testruns: list[Testrun],
57+
testruns: list[test_results_parser.Testrun],
5658
):
5759
bq_service = get_bigquery_service()
5860

ta_storage/pg.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
from __future__ import annotations
2+
13
from datetime import date, datetime
24
from typing import Any, Literal, TypedDict
35

6+
import test_results_parser
47
from sqlalchemy.dialects.postgresql import insert
58
from sqlalchemy.orm import Session
6-
from test_results_parser import Testrun
79

810
from database.models import (
911
DailyTestRollup,
@@ -51,7 +53,7 @@ def modify_structures(
5153
test_instances_to_write: list[dict[str, Any]],
5254
test_flag_bridge_data: list[dict],
5355
daily_totals: dict[str, DailyTotals],
54-
testrun: Testrun,
56+
testrun: test_results_parser.Testrun,
5557
upload: Upload,
5658
repoid: int,
5759
branch: str | None,
@@ -104,7 +106,7 @@ def modify_structures(
104106
def generate_test_dict(
105107
test_id: str,
106108
repoid: int,
107-
testrun: Testrun,
109+
testrun: test_results_parser.Testrun,
108110
flags_hash: str,
109111
framework: str | None,
110112
) -> dict[str, Any]:
@@ -123,7 +125,7 @@ def generate_test_dict(
123125
def generate_test_instance_dict(
124126
test_id: str,
125127
upload: Upload,
126-
testrun: Testrun,
128+
testrun: test_results_parser.Testrun,
127129
commit_sha: str,
128130
branch: str | None,
129131
repoid: int,
@@ -142,13 +144,11 @@ def generate_test_instance_dict(
142144

143145

144146
def update_daily_totals(
145-
daily_totals: dict,
147+
daily_totals: dict[str, DailyTotals],
146148
test_id: str,
147149
duration_seconds: float | None,
148150
outcome: Literal["pass", "failure", "error", "skip"],
149151
):
150-
daily_totals[test_id]["last_duration_seconds"] = duration_seconds
151-
152152
# logic below is a little complicated but we're basically doing:
153153

154154
# (old_avg * num of values used to compute old avg) + new value
@@ -192,8 +192,8 @@ def create_daily_totals(
192192
daily_totals[test_id] = {
193193
"test_id": test_id,
194194
"repoid": repoid,
195-
"last_duration_seconds": duration_seconds,
196-
"avg_duration_seconds": duration_seconds,
195+
"last_duration_seconds": duration_seconds or 0.0,
196+
"avg_duration_seconds": duration_seconds or 0.0,
197197
"pass_count": 1 if outcome == "pass" else 0,
198198
"fail_count": 1 if outcome == "failure" or outcome == "error" else 0,
199199
"skip_count": 1 if outcome == "skip" else 0,
@@ -290,7 +290,7 @@ def write_testruns(
290290
branch_name: str,
291291
upload: Upload,
292292
framework: str | None,
293-
testruns: list[Testrun],
293+
testruns: list[test_results_parser.Testrun],
294294
):
295295
tests_to_write: dict[str, dict[str, Any]] = {}
296296
test_instances_to_write: list[dict[str, Any]] = []
@@ -326,6 +326,3 @@ def write_testruns(
326326

327327
if len(test_instances_to_write) > 0:
328328
save_test_instances(self.db_session, test_instances_to_write)
329-
330-
upload.state = "v2_persisted"
331-
self.db_session.commit()

ta_storage/tests/test_bq.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
from __future__ import annotations
2+
13
from datetime import datetime
24
from unittest.mock import MagicMock, patch
35

46
import pytest
5-
from test_results_parser import Testrun
7+
import test_results_parser
68

79
import generated_proto.testrun.ta_testrun_pb2 as ta_testrun_pb2
810
from database.tests.factories import RepositoryFlagFactory, UploadFactory
@@ -38,7 +40,7 @@ def test_bigquery_driver(dbsession, mock_bigquery_service):
3840
upload.flags.append(repo_flag_2)
3941
dbsession.flush()
4042

41-
test_data: list[Testrun] = [
43+
test_data: list[test_results_parser.Testrun] = [
4244
{
4345
"name": "test_name",
4446
"classname": "test_class",

tasks/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
from tasks.sync_repo_languages_gql import sync_repo_languages_gql_task
5050
from tasks.sync_repos import sync_repos_task
5151
from tasks.sync_teams import sync_teams_task
52+
from tasks.ta_finisher import ta_finisher_task
53+
from tasks.ta_processor import ta_processor_task
5254
from tasks.test_results_finisher import test_results_finisher_task
5355
from tasks.test_results_processor import test_results_processor_task
5456
from tasks.timeseries_backfill import (

0 commit comments

Comments
 (0)