Bug 1328453 - Only use completed jobs for calculating average job duration

Completed jobs = those with an end time > start_time
This commit is contained in:
William Lachance 2017-03-03 15:59:45 -05:00 коммит произвёл William Lachance
Родитель fe5742a236
Коммит 1a19c1601a
2 изменённых файлов: 16 добавлений и 2 удалений

Просмотреть файл

@ -42,3 +42,15 @@ def test_calculate_durations(test_repository, failure_classifications,
assert len(durations) == 1
expected_duration = int(round((first_job_duration + second_job_duration) / 2))
assert durations[0].average_duration == expected_duration
# Add a fake job with an end time > start time, verify that it is
# ignored and average duration remains the same
third_job = job_data(revision=result_set_stored[0]['revision'],
start_timestamp=now,
end_timestamp=now - second_job_duration,
job_guid='another-unique-guid')
store_job_data(test_repository, [third_job])
call_command('calculate_durations')
durations = JobDuration.objects.all()
assert len(durations) == 1
assert durations[0].average_duration == expected_duration

Просмотреть файл

@ -14,7 +14,8 @@ from django.core.cache import cache
from django.core.validators import MinLengthValidator
from django.db import (models,
transaction)
from django.db.models import (Q,
from django.db.models import (F,
Q,
Case,
Count,
When)
@ -572,7 +573,8 @@ class JobManager(models.Manager):
num_jobs = 0
total_time = 0.0
for (start_time, end_time) in jobs.filter(
signature__signature=signature_hash).values_list(
signature__signature=signature_hash,
end_time__gt=F('start_time')).values_list(
'start_time', 'end_time'):
total_time += (end_time - start_time).total_seconds()
num_jobs += 1