Skip to content

Commit

Permalink
fix job start timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
TupleType committed Jun 26, 2022
1 parent 916b628 commit 8289e53
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
from time import sleep, time
from uuid import uuid4

# import logging
# import http.client

OWNER = 'Wonderland'
REPOSITORIES_DIR = Path(__file__).resolve().parent / 'repositories'
GITEA_GIT_BASE = 'http://thealice:thealice@localhost:3000'
RUNNING_BUILD_TIMEOUT = 210
START_BUILD_TIMEOUT = 60
START_BUILD_TIMEOUT = 40
FORK_ORG = 'test'
GITEA_BASE = 'http://localhost:3000'
GITEA_API_BASE = f'{GITEA_BASE}/api/v1'
Expand Down Expand Up @@ -73,14 +70,28 @@ def get(self, endpoint, **kwargs):
return self.requester.get_url(f'{self.baseurl}{endpoint}', **kwargs)

def find_in_last_build_console(self, job_path, string, start_job=True):
if start_job:
res = self.post(f'/job/{job_path}/build?delay=0')
assert res.status_code == 200 or res.status_code == 201

if '/job/' in job_path:
job_name = f'{job_path.split("/")[0]}/{job_path.split("/")[-1]}'
else:
job_name = job_path
if start_job:
res = self.post(f'/job/{job_path}/build?delay=0')
assert res.status_code == 200 or res.status_code == 201
start_time = time()
retried = False
while 1:
if True not in [job.is_queued_or_running() for name, job in self.get_jobs() if job_name in name]:
if time() - start_time > START_BUILD_TIMEOUT:
if not retried:
retried = True
res = self.post(f'/job/{job_path}/build?delay=0')
assert res.status_code == 200 or res.status_code == 201
start_time = time()
else:
break
sleep(1)
continue
break

def search_last_build(job):
start = time()
Expand All @@ -104,19 +115,15 @@ def search_last_build(job):
try:
last_build = job.get_last_build()
except NoBuildData:
return False, ''
return False, str(NoBuildData)
if string in last_build.get_console():
return True, ''
return False, last_build.get_console()

start_time = time()
while 1:
results = [search_last_build(job) for name, job in self.get_jobs()
if job_name in name]
if [result for result, console in results if result]:
return True
if time() - start_time > START_BUILD_TIMEOUT:
break
results = [search_last_build(job) for name, job in self.get_jobs()
if job_name in name]
if [result for result, console in results if result]:
return True
print('--------------------------\n'.join([console for result, console in results if console]))
return False

Expand Down

0 comments on commit 8289e53

Please sign in to comment.