|
7 | 7 | from . import utils
|
8 | 8 | from .utils import lazy_debug
|
9 | 9 | import logging
|
10 |
| -from threading import Thread, Lock |
| 10 | +from threading import Thread, Lock, Timer |
11 | 11 | import time
|
12 | 12 | import traceback
|
13 | 13 | import sqlite3
|
@@ -128,7 +128,8 @@ def __init__(self, num, head_sha, status, db, repo_label, mergeable_que,
|
128 | 128 | self.owner = owner
|
129 | 129 | self.name = name
|
130 | 130 | self.repos = repos
|
131 |
| - self.test_started = time.time() # FIXME: Save in the local database |
| 131 | + self.timeout_timer = None |
| 132 | + self.test_started = time.time() |
132 | 133 |
|
133 | 134 | def head_advanced(self, head_sha, *, use_db=True):
|
134 | 135 | self.head_sha = head_sha
|
@@ -179,6 +180,9 @@ def add_comment(self, text):
|
179 | 180 |
|
180 | 181 | def set_status(self, status):
|
181 | 182 | self.status = status
|
| 183 | + if self.timeout_timer: |
| 184 | + self.timeout_timer.cancel() |
| 185 | + self.timeout_timer = None |
182 | 186 |
|
183 | 187 | db_query(
|
184 | 188 | self.db,
|
@@ -320,6 +324,30 @@ def blocked_by_closed_tree(self):
|
320 | 324 | treeclosed = self.repos[self.repo_label].treeclosed
|
321 | 325 | return treeclosed if self.priority < treeclosed else None
|
322 | 326 |
|
| 327 | + def start_testing(self, timeout): |
| 328 | + self.test_started = time.time() # FIXME: Save in the local database |
| 329 | + self.set_status('pending') |
| 330 | + timer = Timer(timeout, self.timed_out) |
| 331 | + timer.start() |
| 332 | + self.timeout_timer = timer |
| 333 | + |
| 334 | + def timed_out(self): |
| 335 | + print('* Test timed out: {}'.format(self)) |
| 336 | + |
| 337 | + self.merge_sha = '' |
| 338 | + self.save() |
| 339 | + self.set_status('failure') |
| 340 | + |
| 341 | + desc = 'Test timed out' |
| 342 | + utils.github_create_status( |
| 343 | + self.get_repo(), |
| 344 | + self.head_sha, |
| 345 | + 'failure', |
| 346 | + '', |
| 347 | + desc, |
| 348 | + context='homu') |
| 349 | + self.add_comment(':boom: {}'.format(desc)) |
| 350 | + |
323 | 351 |
|
324 | 352 | def sha_cmp(short, full):
|
325 | 353 | return len(short) >= 4 and short == full[:len(short)]
|
@@ -1140,8 +1168,7 @@ def start_build(state, repo_cfgs, buildbot_slots, logger, db, git_cfg):
|
1140 | 1168 | branch,
|
1141 | 1169 | state.merge_sha))
|
1142 | 1170 |
|
1143 |
| - state.test_started = time.time() |
1144 |
| - state.set_status('pending') |
| 1171 | + state.start_testing(TEST_TIMEOUT) |
1145 | 1172 |
|
1146 | 1173 | desc = '{} commit {} with merge {}...'.format(
|
1147 | 1174 | 'Trying' if state.try_ else 'Testing',
|
@@ -1217,8 +1244,7 @@ def start_rebuild(state, repo_cfgs):
|
1217 | 1244 | state.add_comment(':bomb: Failed to start rebuilding: `{}`'.format(err)) # noqa
|
1218 | 1245 | return False
|
1219 | 1246 |
|
1220 |
| - state.test_started = time.time() |
1221 |
| - state.set_status('pending') |
| 1247 | + state.start_testing(TEST_TIMEOUT) |
1222 | 1248 |
|
1223 | 1249 | msg_1 = 'Previous build results'
|
1224 | 1250 | msg_2 = ' for {}'.format(', '.join('[{}]({})'.format(builder, url) for builder, url in succ_builders)) # noqa
|
@@ -1326,39 +1352,6 @@ def fetch_mergeability(mergeable_que):
|
1326 | 1352 | mergeable_que.task_done()
|
1327 | 1353 |
|
1328 | 1354 |
|
1329 |
| -def check_timeout(states, queue_handler): |
1330 |
| - while True: |
1331 |
| - try: |
1332 |
| - for repo_label, repo_states in states.items(): |
1333 |
| - for num, state in repo_states.items(): |
1334 |
| - _timout = time.time() - state.test_started >= TEST_TIMEOUT |
1335 |
| - if state.status == 'pending' and _timout: |
1336 |
| - print('* Test timed out: {}'.format(state)) |
1337 |
| - |
1338 |
| - state.merge_sha = '' |
1339 |
| - state.save() |
1340 |
| - state.set_status('failure') |
1341 |
| - |
1342 |
| - desc = 'Test timed out' |
1343 |
| - utils.github_create_status( |
1344 |
| - state.get_repo(), |
1345 |
| - state.head_sha, |
1346 |
| - 'failure', |
1347 |
| - '', |
1348 |
| - desc, |
1349 |
| - context='homu') |
1350 |
| - state.add_comment(':boom: {}'.format(desc)) |
1351 |
| - |
1352 |
| - queue_handler() |
1353 |
| - |
1354 |
| - except Exception: |
1355 |
| - print('* Error while checking timeout') |
1356 |
| - traceback.print_exc() |
1357 |
| - |
1358 |
| - finally: |
1359 |
| - time.sleep(3600) |
1360 |
| - |
1361 |
| - |
1362 | 1355 | def synchronize(repo_label, repo_cfg, logger, gh, states, repos, db, mergeable_que, my_username, repo_labels): # noqa
|
1363 | 1356 | logger.info('Synchronizing {}...'.format(repo_label))
|
1364 | 1357 |
|
@@ -1666,7 +1659,6 @@ def queue_handler():
|
1666 | 1659 | ]).start()
|
1667 | 1660 |
|
1668 | 1661 | Thread(target=fetch_mergeability, args=[mergeable_que]).start()
|
1669 |
| - Thread(target=check_timeout, args=[states, queue_handler]).start() |
1670 | 1662 |
|
1671 | 1663 | queue_handler()
|
1672 | 1664 |
|
|
0 commit comments