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

Commit 9d5c620

Browse files
committed
feat(ta-gql): handle receiving all branches filter
add all branches special case for TA results branch filter in new TA functionality
1 parent 854e334 commit 9d5c620

File tree

4 files changed

+148
-5
lines changed

4 files changed

+148
-5
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
[
2+
{
3+
"cursor": "MC44fHRlc3Q0",
4+
"node": {
5+
"name": "test4",
6+
"failureRate": 0.8,
7+
"flakeRate": 0.0,
8+
"avgDuration": 100.0,
9+
"totalFailCount": 20,
10+
"totalFlakyFailCount": 0,
11+
"totalPassCount": 5,
12+
"totalSkipCount": 5,
13+
"commitsFailed": 5,
14+
"lastDuration": 100.0
15+
}
16+
},
17+
{
18+
"cursor": "MC43NXx0ZXN0Mw==",
19+
"node": {
20+
"name": "test3",
21+
"failureRate": 0.75,
22+
"flakeRate": 0.0,
23+
"avgDuration": 100.0,
24+
"totalFailCount": 15,
25+
"totalFlakyFailCount": 0,
26+
"totalPassCount": 5,
27+
"totalSkipCount": 5,
28+
"commitsFailed": 5,
29+
"lastDuration": 100.0
30+
}
31+
},
32+
{
33+
"cursor": "MC42NjY2NjY2NjY2NjY2NjY2fHRlc3Qy",
34+
"node": {
35+
"name": "test2",
36+
"failureRate": 0.6666666666666666,
37+
"flakeRate": 0.0,
38+
"avgDuration": 100.0,
39+
"totalFailCount": 10,
40+
"totalFlakyFailCount": 0,
41+
"totalPassCount": 5,
42+
"totalSkipCount": 5,
43+
"commitsFailed": 5,
44+
"lastDuration": 100.0
45+
}
46+
},
47+
{
48+
"cursor": "MC41fHRlc3Qx",
49+
"node": {
50+
"name": "test1",
51+
"failureRate": 0.5,
52+
"flakeRate": 0.5,
53+
"avgDuration": 100.0,
54+
"totalFailCount": 5,
55+
"totalFlakyFailCount": 5,
56+
"totalPassCount": 5,
57+
"totalSkipCount": 5,
58+
"commitsFailed": 5,
59+
"lastDuration": 100.0
60+
}
61+
},
62+
{
63+
"cursor": "MC4wfHRlc3Qw",
64+
"node": {
65+
"name": "test0",
66+
"failureRate": 0.0,
67+
"flakeRate": 0.0,
68+
"avgDuration": 100.0,
69+
"totalFailCount": 0,
70+
"totalFlakyFailCount": 0,
71+
"totalPassCount": 5,
72+
"totalSkipCount": 5,
73+
"commitsFailed": 5,
74+
"lastDuration": 100.0
75+
}
76+
}
77+
]

graphql_api/tests/test_test_analytics.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,3 +808,68 @@ def test_gql_query_with_new_ta(self, mocker, repository, snapshot):
808808
settings.GCS_BUCKET_NAME,
809809
f"test_analytics/branch_rollups/{repository.repoid}/{repository.branch}.arrow",
810810
)
811+
812+
def test_gql_query_with_new_ta_all_branches(self, mocker, repository, snapshot):
813+
# set the feature flag
814+
mocker.patch("rollouts.READ_NEW_TA.check_value", return_value=True)
815+
816+
# read file from samples
817+
storage = get_appropriate_storage_service()
818+
try:
819+
storage.create_root_storage(settings.GCS_BUCKET_NAME)
820+
except BucketAlreadyExistsError:
821+
pass
822+
storage.write_file(
823+
settings.GCS_BUCKET_NAME,
824+
f"test_analytics/repo_rollups/{repository.repoid}.arrow",
825+
test_results_table_no_version.write_ipc(None).getvalue(),
826+
)
827+
828+
# run the GQL query
829+
query = base_gql_query % (
830+
repository.author.username,
831+
repository.name,
832+
"""
833+
testResults(filters: { branch: "All branches" }, ordering: { parameter: FAILURE_RATE, direction: DESC } ) {
834+
totalCount
835+
edges {
836+
cursor
837+
node {
838+
name
839+
failureRate
840+
flakeRate
841+
updatedAt
842+
avgDuration
843+
totalFailCount
844+
totalFlakyFailCount
845+
totalPassCount
846+
totalSkipCount
847+
commitsFailed
848+
lastDuration
849+
}
850+
}
851+
}
852+
""",
853+
)
854+
855+
result = self.gql_request(query, owner=repository.author)
856+
857+
# take a snapshot of the results
858+
assert (
859+
result["owner"]["repository"]["testAnalytics"]["testResults"]["totalCount"]
860+
== 5
861+
)
862+
assert snapshot("json") == [
863+
{
864+
**edge,
865+
"node": {k: v for k, v in edge["node"].items() if k != "updatedAt"},
866+
}
867+
for edge in result["owner"]["repository"]["testAnalytics"]["testResults"][
868+
"edges"
869+
]
870+
]
871+
872+
storage.delete_file(
873+
settings.GCS_BUCKET_NAME,
874+
f"test_analytics/repo_rollups/{repository.repoid}.arrow",
875+
)

graphql_api/types/test_analytics/test_analytics.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ def generate_test_results(
198198
199199
:param repoid: repoid of the repository we want to calculate aggregates for
200200
:param branch: optional name of the branch we want to filter on, if this is provided the aggregates calculated will only take into account
201-
test instances generated on that branch. By default branches will not be filtered and test instances on all branches wil be taken into
202-
account.
201+
test instances generated on that branch.
203202
:param interval: timedelta for filtering test instances used to calculate the aggregates by time, the test instances used will be
204203
those with a created at larger than now - interval.
205204
:param testsuites: optional list of testsuite names to filter by, this is done via a union

utils/test_results.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from rollouts import READ_NEW_TA
1212
from services.task import TaskService
1313

14+
ALL_BRANCHES = "All branches"
15+
1416
get_results_summary = Summary(
1517
"test_results_get_results", "Time it takes to download results from GCS", ["impl"]
1618
)
@@ -144,10 +146,10 @@ def old_get_results(
144146
return table
145147

146148

147-
def rollup_blob_path(repoid: int, branch: str | None = None) -> str:
149+
def rollup_blob_path(repoid: int, branch: str) -> str:
148150
return (
149151
f"test_analytics/branch_rollups/{repoid}/{branch}.arrow"
150-
if branch
152+
if branch != ALL_BRANCHES
151153
else f"test_analytics/repo_rollups/{repoid}.arrow"
152154
)
153155

@@ -223,7 +225,7 @@ def v1_agg_table(table: pl.LazyFrame) -> pl.LazyFrame:
223225

224226
def new_get_results(
225227
repoid: int,
226-
branch: str | None,
228+
branch: str,
227229
interval_start: int,
228230
interval_end: int | None = None,
229231
) -> pl.DataFrame | None:

0 commit comments

Comments
 (0)