mirror of
https://github.com/karma-riuk/crab.git
synced 2025-07-05 05:28:13 +02:00
created a timeout to stop tests from running when
they take ages
This commit is contained in:
36
handlers.py
36
handlers.py
@ -1,5 +1,5 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
import os, re, docker, subprocess
|
import os, re, docker, signal
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
USER_ID = os.getuid() # for container user
|
USER_ID = os.getuid() # for container user
|
||||||
@ -71,20 +71,32 @@ class BuildHandler(ABC):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def test_repo(self) -> bool:
|
def test_repo(self) -> bool:
|
||||||
exec_result = self.container.exec_run(self.test_cmd())
|
def timeout_handler(signum, frame):
|
||||||
output = clean_output(exec_result.output)
|
raise TimeoutError("Tests exceeded time limit")
|
||||||
if exec_result.exit_code != 0:
|
|
||||||
self.updates["tested_successfully"] = False
|
signal.signal(signal.SIGALRM, timeout_handler)
|
||||||
|
signal.alarm(3600) # Set timeout to 1 hour (3600 seconds)
|
||||||
|
|
||||||
|
try:
|
||||||
|
exec_result = self.container.exec_run(self.test_cmd())
|
||||||
|
output = clean_output(exec_result.output)
|
||||||
|
if exec_result.exit_code != 0:
|
||||||
|
self.updates["tested_successfully"] = False
|
||||||
|
self.updates["error_msg"] = output
|
||||||
|
return False
|
||||||
|
|
||||||
|
self.updates["tested_successfully"] = True
|
||||||
self.updates["error_msg"] = output
|
self.updates["error_msg"] = output
|
||||||
|
|
||||||
|
return self.extract_test_numbers(output)
|
||||||
|
|
||||||
|
except TimeoutError:
|
||||||
|
self.updates["tested_successfully"] = False
|
||||||
|
self.updates["error_msg"] = "Test process killed due to exceeding the 1-hour time limit"
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.updates["tested_successfully"] = True
|
|
||||||
self.updates["error_msg"] = output
|
|
||||||
|
|
||||||
extracted_successfully = self.extract_test_numbers(output)
|
finally:
|
||||||
|
signal.alarm(0) # Cancel the alarm
|
||||||
|
|
||||||
return extracted_successfully
|
|
||||||
|
|
||||||
def clean_repo(self) -> None:
|
def clean_repo(self) -> None:
|
||||||
self.container.exec_run(self.clean_cmd())
|
self.container.exec_run(self.clean_cmd())
|
||||||
|
Reference in New Issue
Block a user