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

Commit a0d9959

Browse files
Mkerge branch 'main' of github.com:codecov/codecov-api into 2591-ba-endpoint-expects-storage-path
2 parents 98d2583 + 7da1080 commit a0d9959

File tree

7 files changed

+106
-1
lines changed

7 files changed

+106
-1
lines changed

graphql_api/tests/test_test_result.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ def setUp(self):
3131
date=date.today() - timedelta(days=2),
3232
avg_duration_seconds=0.6,
3333
latest_run=datetime.now() - timedelta(days=2),
34+
flaky_fail_count=0,
3435
)
3536
_ = DailyTestRollupFactory(
3637
test=self.test,
3738
commits_where_fail=["123", "456"],
3839
date=datetime.now() - timedelta(days=1),
3940
avg_duration_seconds=2,
4041
latest_run=datetime.now() - timedelta(days=1),
42+
flaky_fail_count=1,
4143
)
4244
_ = DailyTestRollupFactory(
4345
test=self.test,
@@ -46,6 +48,7 @@ def setUp(self):
4648
last_duration_seconds=5.0,
4749
avg_duration_seconds=3,
4850
latest_run=datetime.now(),
51+
flaky_fail_count=1,
4952
)
5053

5154
def test_fetch_test_result_name(self) -> None:
@@ -354,3 +357,34 @@ def test_fetch_test_result_total_pass_count(self) -> None:
354357
]["totalPassCount"]
355358
== 3
356359
)
360+
361+
def test_fetch_test_result_total_flaky_fail_count(self) -> None:
362+
query = """
363+
query {
364+
owner(username: "%s") {
365+
repository(name: "%s") {
366+
... on Repository {
367+
testAnalytics {
368+
testResults {
369+
edges {
370+
node {
371+
totalFlakyFailCount
372+
}
373+
}
374+
}
375+
}
376+
}
377+
}
378+
}
379+
}
380+
""" % (self.owner.username, self.repository.name)
381+
382+
result = self.gql_request(query, owner=self.owner)
383+
384+
assert "errors" not in result
385+
assert (
386+
result["owner"]["repository"]["testAnalytics"]["testResults"]["edges"][0][
387+
"node"
388+
]["totalFlakyFailCount"]
389+
== 2
390+
)

graphql_api/tests/test_test_results_headers.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,30 @@ def test_fetch_test_result_skipped_tests(self) -> None:
137137
]
138138
== 29
139139
)
140+
141+
def test_fetch_test_result_slow_tests(self) -> None:
142+
query = """
143+
query {
144+
owner(username: "%s") {
145+
repository(name: "%s") {
146+
... on Repository {
147+
testAnalytics {
148+
testResultsAggregates {
149+
totalSlowTests
150+
}
151+
}
152+
}
153+
}
154+
}
155+
}
156+
""" % (self.owner.username, self.repository.name)
157+
158+
result = self.gql_request(query, owner=self.owner)
159+
160+
assert "errors" not in result
161+
assert (
162+
result["owner"]["repository"]["testAnalytics"]["testResultsAggregates"][
163+
"totalSlowTests"
164+
]
165+
== 1
166+
)

graphql_api/types/test_results/test_results.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type TestResult {
77
avgDuration: Float!
88
lastDuration: Float!
99
totalFailCount: Int!
10+
totalFlakyFailCount: Int!
1011
totalSkipCount: Int!
1112
totalPassCount: Int!
1213
}

graphql_api/types/test_results/test_results.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class TestDict(TypedDict):
1414
last_duration: float
1515
flake_rate: float
1616
total_fail_count: int
17+
total_flaky_fail_count: int
1718
total_skip_count: int
1819
total_pass_count: int
1920
computed_name: str | None
@@ -62,6 +63,11 @@ def resolve_total_fail_count(test: TestDict, _: GraphQLResolveInfo) -> int:
6263
return test["total_fail_count"]
6364

6465

66+
@test_result_bindable.field("totalFlakyFailCount")
67+
def resolve_total_flaky_fail_count(test: TestDict, _: GraphQLResolveInfo) -> int:
68+
return test["total_flaky_fail_count"]
69+
70+
6571
@test_result_bindable.field("totalSkipCount")
6672
def resolve_total_skip_count(test: TestDict, _: GraphQLResolveInfo) -> int:
6773
return test["total_skip_count"]

graphql_api/types/test_results_aggregates/test_results_aggregates.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class TestResultsAggregates(TypedDict):
1111
total_duration_percent_change: float | None
1212
slowest_tests_duration: float
1313
slowest_tests_duration_percent_change: float | None
14+
total_slow_tests: int
15+
total_slow_tests_percent_change: float | None
1416
fails: int
1517
fails_percent_change: float | None
1618
skips: int
@@ -43,6 +45,18 @@ def resolve_slowest_tests_duration_percent_change(
4345
return obj.get("slowest_tests_duration_percent_change")
4446

4547

48+
@test_results_aggregates_bindable.field("totalSlowTests")
49+
def resolve_total_slow_tests(obj: TestResultsAggregates, _: GraphQLResolveInfo) -> int:
50+
return obj["total_slow_tests"]
51+
52+
53+
@test_results_aggregates_bindable.field("totalSlowTestsPercentChange")
54+
def resolve_total_slow_tests_percent_change(
55+
obj: TestResultsAggregates, _: GraphQLResolveInfo
56+
) -> float | None:
57+
return obj.get("total_slow_tests_percent_change")
58+
59+
4660
@test_results_aggregates_bindable.field("totalFails")
4761
def resolve_total_fails(obj: TestResultsAggregates, _: GraphQLResolveInfo) -> int:
4862
return obj["fails"]

utils/test_results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
def slow_test_threshold(total_tests: int) -> int:
3434
percentile = (100 - SLOW_TEST_PERCENTILE) / 100
3535
slow_tests_to_return = floor(percentile * total_tests)
36-
return max(slow_tests_to_return, 1)
36+
return min(max(slow_tests_to_return, 1), 100)
3737

3838

3939
class ArrayLength(Func):
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pytest
2+
3+
from utils.test_results import slow_test_threshold
4+
5+
6+
@pytest.mark.parametrize(
7+
"total_tests, expected_threshold",
8+
[
9+
(0, 1),
10+
(1, 1),
11+
(10, 1),
12+
(100, 5),
13+
(1000, 50),
14+
(10000, 100),
15+
(1000000, 100),
16+
(20, 1),
17+
(50, 2),
18+
(200, 10),
19+
(2000, 100),
20+
],
21+
)
22+
def test_slow_test_threshold(total_tests, expected_threshold):
23+
assert slow_test_threshold(total_tests) == expected_threshold

0 commit comments

Comments
 (0)