Skip to content

Commit

Permalink
Merge pull request mozilla#305 from adusca/failed_jobs
Browse files Browse the repository at this point in the history
Also count failed jobs as potential jobs
  • Loading branch information
adusca committed Aug 3, 2015
2 parents eebc530 + 5898899 commit 4e647c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
20 changes: 11 additions & 9 deletions mozci/mozci.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
build_talos_buildernames_for_repo
from mozci.sources import allthethings, buildapi, buildjson, pushlog
from mozci.query_jobs import PENDING, RUNNING, SUCCESS, UNKNOWN,\
COALESCED, BuildApi, TreeherderApi
COALESCED, WARNING, FAILURE, EXCEPTION, RETRY, BuildApi, TreeherderApi
from mozci.utils.misc import _all_urls_reachable
from mozci.utils.transfer import path_to_file, clean_directory

Expand Down Expand Up @@ -65,21 +65,22 @@ def _status_summary(jobs):
pending = 0
running = 0
coalesced = 0
failed = 0

for job in jobs:
status = QUERY_SOURCE.get_job_status(job)
if status == PENDING:
pending += 1
if status == RUNNING:
if status in (RUNNING, UNKNOWN):
running += 1
if status == SUCCESS:
successful += 1
if status == COALESCED:
coalesced += 1
if status == UNKNOWN:
running += 1
if status in (FAILURE, WARNING, EXCEPTION, RETRY):
failed += 1

return (successful, pending, running, coalesced)
return (successful, pending, running, coalesced, failed)


def _determine_trigger_objective(revision, buildername, trigger_build_if_missing=True):
Expand Down Expand Up @@ -385,11 +386,12 @@ def trigger_range(buildername, revisions, times=1, dry_run=False,

# 1) How many potentially completed jobs can we get for this buildername?
matching_jobs = QUERY_SOURCE.get_matching_jobs(repo_name, rev, buildername)
successful_jobs, pending_jobs, running_jobs = _status_summary(matching_jobs)[0:3]
successful_jobs, pending_jobs, running_jobs, _, failed_jobs = _status_summary(matching_jobs)

potential_jobs = pending_jobs + running_jobs + successful_jobs
LOG.debug("We found %d pending jobs, %d running jobs and %d successful_jobs." %
(pending_jobs, running_jobs, successful_jobs))
potential_jobs = pending_jobs + running_jobs + successful_jobs + failed_jobs
# TODO: change this debug message when we have a less hardcoded _status_summary
LOG.debug("We found %d pending/running jobs, %d successful jobs and "
"%d failed jobs" % (pending_jobs + running_jobs, successful_jobs, failed_jobs))

if potential_jobs >= times:
LOG.info("We have %d job(s) for '%s' which is enough for the %d job(s) we want." %
Expand Down
8 changes: 4 additions & 4 deletions test/test_mozci.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,22 @@ def test_status_summary_successful(self, get_status):
We will only test _status_summary with simple mocks of get_job_status here.
This test is with a success state.
"""
assert mozci.mozci._status_summary(self.jobs) == (1, 0, 0, 0)
assert mozci.mozci._status_summary(self.jobs) == (1, 0, 0, 0, 0)

@patch('mozci.query_jobs.BuildApi.get_job_status',
return_value=PENDING)
def test_status_summary_pending(self, get_status):
"""Test _status_summary with a running state."""
assert mozci.mozci._status_summary(self.jobs) == (0, 1, 0, 0)
assert mozci.mozci._status_summary(self.jobs) == (0, 1, 0, 0, 0)

@patch('mozci.query_jobs.BuildApi.get_job_status',
return_value=RUNNING)
def test_status_summary_running(self, get_status):
"""Test _status_summary with a running state."""
assert mozci.mozci._status_summary(self.jobs) == (0, 0, 1, 0)
assert mozci.mozci._status_summary(self.jobs) == (0, 0, 1, 0, 0)

@patch('mozci.query_jobs.BuildApi.get_job_status',
return_value=COALESCED)
def test_status_summary_coalesced(self, get_status):
"""Test _status_summary with a coalesced state."""
assert mozci.mozci._status_summary(self.jobs) == (0, 0, 0, 1)
assert mozci.mozci._status_summary(self.jobs) == (0, 0, 0, 1, 0)

0 comments on commit 4e647c0

Please sign in to comment.