Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions kcidev/libs/maestro_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def maestro_watch_jobs(baseurl, token, treeid, job_filter, test, root_node="chec
logging.debug(f"Watching jobs: {job_filter}, test: {test}")
previous_nodes = None
running = False
jobs_done_ts = None

job_info = {}
for job in job_filter:
Expand All @@ -248,7 +249,9 @@ def maestro_watch_jobs(baseurl, token, treeid, job_filter, test, root_node="chec
kci_warning("No nodes found. Retrying...")
time.sleep(5)
continue
if previous_nodes == nodes:
# Keep checking the test-result deadline after the jobs have completed,
# even when the API response has not changed.
if previous_nodes == nodes and jobs_done_ts is None:
logging.debug("No changes in nodes, waiting...")
kci_msg_nonl(".")
time.sleep(30)
Expand All @@ -260,7 +263,6 @@ def maestro_watch_jobs(baseurl, token, treeid, job_filter, test, root_node="chec
# Tricky part in watch is that we might have one item in job_filter (job, test),
# but it might spawn multiple nodes with same name
test_result = None
jobs_done_ts = None
logging.debug(f"Processing {len(nodes)} nodes")
for node in nodes:
if node["name"] == test:
Expand Down Expand Up @@ -304,7 +306,7 @@ def maestro_watch_jobs(baseurl, token, treeid, job_filter, test, root_node="chec
if not test:
return
else:
if not jobs_done_ts:
if jobs_done_ts is None:
jobs_done_ts = time.time()
logging.debug("All jobs done, waiting for test results")
# if all jobs done, usually test results must be available
Expand All @@ -321,6 +323,10 @@ def maestro_watch_jobs(baseurl, token, treeid, job_filter, test, root_node="chec
elif test_result:
logging.info(f"Test {test} failed with result: {test_result}")
sys.exit(1)
else:
logging.error(f"Test {test} result was not available after 60s")
kci_err(f"Test {test} result was not available after 60s")
sys.exit(2)

running = True
kci_msg_nonl(f"\rRunning job...")
Expand Down
35 changes: 35 additions & 0 deletions tests/test_maestro_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,38 @@ def test_maestro_watch_jobs_completes_with_patchset_root(monkeypatch):
None,
root_node="patchset",
)


def test_maestro_watch_jobs_times_out_waiting_for_test_result(monkeypatch):
nodes = [
{
"name": "checkout",
"state": "done",
"result": "pass",
"kind": "checkout",
"id": "c1",
"updated": "now",
},
{
"name": "job1",
"state": "done",
"result": "pass",
"kind": "job",
"id": "j1",
"updated": "now",
},
]
monkeypatch.setattr(
maestro_common, "maestro_retrieve_treeid_nodes", Mock(return_value=nodes)
)
monkeypatch.setattr(maestro_common.time, "sleep", Mock())
monkeypatch.setattr(
maestro_common.time, "time", Mock(side_effect=[100, 100, 161, 161, 161])
)

with pytest.raises(SystemExit) as exc_info:
maestro_common.maestro_watch_jobs(
"https://api.example.org/", "token123", "t1", ["job1"], "missing-test"
)

assert exc_info.value.code == 2
Loading