Skip to content

Commit f0bf6cc

Browse files
committed
Ignore failing buildbots that last ran over 14 days ago
1 parent c4533cb commit f0bf6cc

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

buildbotapi.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import json
2+
import time
23
from dataclasses import dataclass
34
from typing import Any, cast
45

56
from aiohttp.client import ClientSession
67

78
JSON = dict[str, Any]
89

10+
# Builders whose most recent build was more than this many days ago
11+
# are considered inactive and ignored when checking for failures
12+
STALE_BUILDER_DAYS = 14
13+
SECONDS_PER_DAY = 24 * 60 * 60
14+
915

1016
@dataclass
1117
class Builder:
@@ -66,6 +72,10 @@ async def is_builder_failing_currently(self, builder: Builder) -> bool:
6672
if not builds:
6773
return False
6874
(build,) = builds
75+
76+
age_days = (time.time() - build["complete_at"]) / SECONDS_PER_DAY
77+
if age_days > STALE_BUILDER_DAYS:
78+
return False
6979
if build["results"] == 2:
7080
return True
7181
return False

tests/test_buildbotapi.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,24 +108,36 @@ async def test_buildbotapi_stable_builders() -> None:
108108
assert "stable" in all_builders[3].tags
109109

110110

111+
# The most recent builds in success.json and failure.json
112+
SUCCESS_COMPLETE_AT = 1728312495
113+
FAILURE_COMPLETE_AT = 1734198808
114+
DAY = buildbotapi.SECONDS_PER_DAY
115+
116+
111117
@pytest.mark.asyncio
112118
@pytest.mark.parametrize(
113-
["json_data", "expected"],
119+
["json_data", "now", "expected"],
114120
[
115-
("tests/buildbotapi/success.json", False),
116-
("tests/buildbotapi/failure.json", True),
117-
("tests/buildbotapi/no-builds.json", False),
121+
# Recent builds: judged on their result
122+
("tests/buildbotapi/success.json", SUCCESS_COMPLETE_AT + DAY, False),
123+
("tests/buildbotapi/failure.json", FAILURE_COMPLETE_AT + DAY, True),
124+
("tests/buildbotapi/no-builds.json", FAILURE_COMPLETE_AT + DAY, False),
125+
# Just inside the staleness cutoff: failure still counts
126+
("tests/buildbotapi/failure.json", FAILURE_COMPLETE_AT + 13 * DAY, True),
127+
# Stale build (last run > 14 days ago): builder ignored
128+
("tests/buildbotapi/failure.json", FAILURE_COMPLETE_AT + 15 * DAY, False),
118129
],
119130
)
120-
async def test_buildbotapi_is_builder_failing_currently_yes(
121-
json_data: str, expected: bool
131+
async def test_buildbotapi_is_builder_failing_currently(
132+
monkeypatch: pytest.MonkeyPatch, json_data: str, now: int, expected: bool
122133
) -> None:
123134
# Arrange
124135
mock_session = AsyncMock(aiohttp.ClientSession)
125136
mock_session.get.return_value.__aenter__.return_value.status = 200
126137
mock_session.get.return_value.__aenter__.return_value.text.return_value = load(
127138
json_data
128139
)
140+
monkeypatch.setattr("buildbotapi.time.time", lambda: now)
129141
api = buildbotapi.BuildBotAPI(mock_session)
130142
builder = buildbotapi.Builder(builderid=3)
131143

0 commit comments

Comments
 (0)