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

Commit f02e4cd

Browse files
fix(ta-gql): get testsuites (#1296)
1 parent 8c6853a commit f02e4cd

File tree

5 files changed

+74
-5
lines changed

5 files changed

+74
-5
lines changed

graphql_api/tests/test_test_analytics.py

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,41 @@ def test_gql_query_flake_aggregates(self, repository, store_in_redis):
744744
"flakeCount": 1,
745745
}
746746

747-
def test_gql_query_with_new_ta(self, mocker, repository, snapshot):
747+
def test_gql_query_test_suites(self, repository, store_in_redis):
748+
query = base_gql_query % (
749+
repository.author.username,
750+
repository.name,
751+
"""
752+
testSuites
753+
""",
754+
)
755+
756+
result = self.gql_request(query, owner=repository.author)
757+
758+
assert sorted(result["owner"]["repository"]["testAnalytics"]["testSuites"]) == [
759+
"testsuite1",
760+
"testsuite2",
761+
"testsuite3",
762+
"testsuite4",
763+
"testsuite5",
764+
]
765+
766+
def test_gql_query_test_suites_term(self, repository, store_in_redis):
767+
query = base_gql_query % (
768+
repository.author.username,
769+
repository.name,
770+
"""
771+
testSuites(term: "testsuite1")
772+
""",
773+
)
774+
775+
result = self.gql_request(query, owner=repository.author)
776+
777+
assert result["owner"]["repository"]["testAnalytics"]["testSuites"] == [
778+
"testsuite1",
779+
]
780+
781+
def test_gql_query_with_new_ta_v1(self, mocker, repository, snapshot):
748782
# set the feature flag
749783
mocker.patch("rollouts.READ_NEW_TA.check_value", return_value=True)
750784

@@ -757,7 +791,8 @@ def test_gql_query_with_new_ta(self, mocker, repository, snapshot):
757791
storage.write_file(
758792
settings.GCS_BUCKET_NAME,
759793
f"test_analytics/branch_rollups/{repository.repoid}/{repository.branch}.arrow",
760-
test_results_table_no_version.write_ipc(None).getvalue(),
794+
test_results_table_v1.write_ipc(None).getvalue(),
795+
metadata={"version": "1"},
761796
)
762797

763798
# run the GQL query
@@ -784,6 +819,18 @@ def test_gql_query_with_new_ta(self, mocker, repository, snapshot):
784819
}
785820
}
786821
}
822+
flakeAggregates {
823+
flakeRate
824+
flakeCount
825+
}
826+
testResultsAggregates {
827+
totalDuration
828+
slowestTestsDuration
829+
totalFails
830+
totalSkips
831+
totalSlowTests
832+
}
833+
testSuites
787834
""",
788835
)
789836

@@ -804,6 +851,28 @@ def test_gql_query_with_new_ta(self, mocker, repository, snapshot):
804851
]
805852
]
806853

854+
assert sorted(result["owner"]["repository"]["testAnalytics"]["testSuites"]) == [
855+
"testsuite0",
856+
"testsuite1",
857+
"testsuite2",
858+
"testsuite3",
859+
"testsuite4",
860+
]
861+
862+
assert result["owner"]["repository"]["testAnalytics"]["flakeAggregates"] == {
863+
"flakeRate": (1 / 15),
864+
"flakeCount": 1,
865+
}
866+
867+
assert result["owner"]["repository"]["testAnalytics"][
868+
"testResultsAggregates"
869+
] == {
870+
"totalDuration": 7500.0,
871+
"slowestTestsDuration": 2500.0,
872+
"totalFails": 50,
873+
"totalSkips": 25,
874+
"totalSlowTests": 1,
875+
}
807876
storage.delete_file(
808877
settings.GCS_BUCKET_NAME,
809878
f"test_analytics/branch_rollups/{repository.repoid}/{repository.branch}.arrow",

graphql_api/types/test_analytics/test_analytics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def get_test_suites(
312312
if table is None:
313313
return []
314314

315-
testsuites = table.select(pl.col("testsuite")).unique()
315+
testsuites = table.select(pl.col("testsuite").explode()).unique()
316316

317317
if term:
318318
testsuites = testsuites.filter(pl.col("testsuite").str.starts_with(term))

graphql_api/types/test_results_aggregates/test_results_aggregates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TestResultsAggregates:
2424

2525

2626
def calculate_aggregates(table: pl.DataFrame) -> pl.DataFrame:
27-
return table.select(
27+
return table.with_columns(pl.col("avg_duration").fill_nan(0)).select(
2828
(
2929
pl.col("avg_duration")
3030
* (pl.col("total_pass_count") + pl.col("total_fail_count"))

utils/test_results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def v1_agg_table(table: pl.LazyFrame) -> pl.LazyFrame:
198198
pl.col("avg_duration") * (pl.col("pass_count") + pl.col("fail_count"))
199199
).sum() / (pl.col("pass_count") + pl.col("fail_count")).sum()
200200

201-
table = table.group_by("computed_name").agg(
201+
table = table.group_by(pl.col("computed_name").alias("name")).agg(
202202
pl.col("testsuite").alias(
203203
"testsuite"
204204
), # TODO: filter by this before we aggregate

0 commit comments

Comments
 (0)